-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[zigpy-integration] - not able to run 2 instances of zigpy-radio module in Domoticz #1117
Comments
looks like the issue is located around the asyncio loop(). Question is how to manage the create_task() in that context. The 1st instance runs and create the event loop, but when the 2nd instance come (the loop already exist), can we get a new loop for the asyncio ? here is the code
|
seems to be the right way
|
Time to time it crashs here
|
Mixing asyncio and threads is tricky. What was not working with the first way you were doing it? Also, you don't need the |
I think that I'm in several issues 1/ embedded python with C++. In regards to you comment, if I do not do |
The same way you run radio_coro = radio_start(self, self._radiomodule, self._serialPort, set_channel=channel, set_extendedPanId=extendedPANID)
loop.run_until_complete(radio_coro) |
so it make the tric. however when starting then 2nd instance with the following code
And with the following code
we are getting this error while starting the 2nd instance
|
Latest code
Does work perfectly for one occurence of a Ziggy instance, but do not work when starting a 2nd instance.
|
reporting to domoticz |
How does Domoticz start a plugin multiple times if |
@dnpwwo if you see this once, your help would be more than welcome. I have created a small plugin.py file to duplicate the issue, which is that I cannot start 2 instances of a plugin running an asyncio.loop(). I'm convinced that it is not about the act that is 2 instances, but more 2 plugins which requires asyncio.loop() |
I don't think they are global to the all Domoticz environment. My understanding is that Domoticz spawn a thread with plugin.py with a given context. When spawning a new thread/plugin it is a total different context. @puddly, @dnpwwo my understanding is when Domoticz start a plugin in a thread , that one is running with its own context, so when a second plugin is started with a new thread , that one is having its own context. |
You are correct, each plugin has both its own thread and own Python interpreter so running copies of a plugin is not a problem in most circumstances. That said the Python documentation describes an interpreter as:
The 'almost' is not fully described but alludes to things external to Python (such as file systems). Modules are a grey area. The doco states:
But a lot of lower level modules are actually compiled C and can therefore do things that the interpreter can't see such as maintain global state and variables which could be the problem here. |
@dnpwwo really appreciate your valuable feedbacks. |
Hi, CC: @dnpwwo |
@dnpwwo PS : I found some sample code to have two interpreter .. I have my test case for the python folks .. it seems two interpreters is risky and might have bugs : https://peps.python.org/pep-0554/#interpreter-isolation |
pipiche38/multiinstances/no_asyncio ( ba6d729 ) |
workaround in place |
if trying to run 2 instances of zigpy-radio module, then the 2nd instance doesn't work !
cc: @puddly, @deufo, @badzz
The text was updated successfully, but these errors were encountered: