Comments (2)
Mixing ascynio with threads can be tricky. So I would avoid that if possible.
Instead of running ChargePoint.heartbeatFunc()
in a new thread you should run it on the event loop of your main thread. For Python 3.7+ you can use asyncio.create_task. Fr older versions you can use asyncio.ensure_future.
async def send_boot_notification(self):
request = call.BootNotificationPayload(
charge_point_model="sample",
charge_point_vendor="test"
)
response = await self.call(request)
#heartbeat on main thread ok
request = call.HeartbeatPayload()
response = await self.call(request)
#send beartbeat on new thread time interval continuously ng
asyncio.create_task(self.heartbeatFunc())
Getting back to the exception in your example: RuntimeError: Task attached to a different loop
.
In order to understand that you must know that tasks and coroutines are executed on an event loop. There are several ways to start an event loop. But normally you start that event loop with asyncio.run in Python 3.7+ or asyncio.run_until_complete if you use an older version of Python.
This event loop is bound to a thread. All the tasks are also bound to that event loop. In the code example you moved moved a coroutine to a different thread to execute it there. That is not possible.
Therefore again my advice to avoid asyncio and threads.
from ocpp.
Amazing!
I have struggled with asyncio / threading for almost a week,
you solve my problem in one line code.
from ocpp.
Related Issues (20)
- Correct v2g serialisation/deserialisation HOT 1
- Remove 2.0 folders HOT 1
- Typo correction in v201.enums.StatusInfoReasonType.value_too_hight -> value_too_high HOT 1
- Bug: in data class definitions for connector_id (not as per specification) HOT 2
- Question about disconnection
- Error with transaction ID HOT 6
- Need example to use Charge point with aiohttp, to create scriptable a chargepoint simulator
- Data transfer from CP to Central HOT 3
- Fix typo in OCPP 2.0.1 enum Action.cost_updated HOT 1
- Modifiying any payload dataclass
- Request timeout issue when ping_interval=None and ping_timeout=None are set.
- Cancel update firmware
- Publishing package to pypi fails.
- deployment aiohttp and websocket in AKS, many Pods?
- Serialization of `call_result.SetVariables` is incorrect when `set_variable_result` attribute contains more than 1 element
- Rejected Trigger Messages HOT 4
- Key name naming style for AnyType data
- TypeError: asdict() should be called on dataclass instances HOT 4
- Blocking call detected HOT 2
- Impossible to get CP connecting to CS HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ocpp.