-
Notifications
You must be signed in to change notification settings - Fork 0
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
gevent breaking threading #167
Comments
As per @Shiny380, @zero88 has started looking on it. And I was also doing some inspections and changes on the project https://github.com/NubeIO/lora-raw same issue. Till now my inspection is:
Working both of us on same task won't be fruitful so I will let @zero88 to work on. Or, if you wanna continue this inspection please let me know. P.S: This task is on priority |
P.S. check this one: https://github.com/NubeIO/lora-raw/pull/29 |
It is my result after make simple test on So, first assumption for After investigate more, I realize: Furthermore, I've not yet looked your code in detail about For PR from @RaiBnod , I don't expect it. It makes custom thread out of server context. If server receive signal to stop/restart, it might stop gunicorn master thread but not for custom thread. And not yet test, but if run in multiple workers, it will call setup db and thread more than one time for each worker, it doesn't share thread context between each workers. |
@zero88 it doesn't make custom thread out of server context, you can see we are wrapping things inside application context. If it was out of that that context, it shows failure on run-time at the db access. Just go with the simple inspection through my PR: NubeIO/lora-raw#29 and test it, it works perfectly fine without any issue like yours in above. If you get any issue let me know and if anything better could you do that's also be appreciated. My inspection is, as I had talked on above: If we make After my change: And lastly, those consecutive two calls on that flow is causing issue. One gets the exact context value, and one gets |
Do you see a problem? @RaiBnod
|
After
|
If you want to manage your threading by yourself, just not use |
moreover, your fix is just tricky workaround to avoid starting thread in worker initialization time, but I'm not sure it works if create new thread in runtime, and
|
If all of you want to leverage the power of |
Even though we use So let come into the conclusion: Issue: It has issue when we have multiple workers. When we do multiple workers turned on our system, all our executable codes gets forked into multiples. In our case, Background tasks are also gets forked into workers numbers. And on our background task we are establishing a connection with MQTT. Since we have multiple workers: it will try to establish multiple connections on the same program. And it shows the issue as:
So, I was running with only one worker. Believing that, we could do some sort solution later on for establishing Do you have any solution for handling this? If you have please do it, otherwise we will proceed with |
Sorry, you're trying your solution with Just use latest code, with my tweak some configuration and follow my setup in It is my result: NubeIO/rubix-bacnet-server#75 Note As I said above, repeat myself:
In case of still want to use
So, to simple for your development, just make changes as I did in NubeIO/rubix-bacnet-server#75 |
gevent monkey patching seems to be breaking threads.
This can be seen in
mqtt_client_base.py
https://github.com/NubeIO/rubix-point-server/blob/master/src/services/mqtt_client/mqtt_client_base.py#L32This line somehow splits the thread into two separate threads. One thread the normal
FlaskThread
and onegevent.threading._DummyThread
. Seems to be linked to accessingthreading.currentThread()
or similar.This is causing a constant reconnection issue for mqtt and probably other issues. It stops happening if
monkey.patch_all()
(https://github.com/NubeIO/rubix-point-server/blob/master/src/server.py#L14) is removed.Debug code from
mqtt_client_base.py
:Output:
Prevent threading being patched with
curious_george.patch_all(thread=False)
:But then the event dispatching across threads breaks in a weird way where it appears to function correctly but the event never gets added to the event queue. The event queue object is the exact same object (address) across the different threads but the loop in the target thread never seems to receive the event.
seen in this line https://github.com/NubeIO/rubix-point-server/blob/master/src/services/event_service_base.py#L70 where it functions correctly on the correct object address but just disappears.
can be seen by calling this function https://github.com/NubeIO/rubix-point-server/blob/master/src/source_drivers/modbus/resources/point/point_singular.py#L88 from a Flask http request
/api/modbus/poll/point
Some links:
The text was updated successfully, but these errors were encountered: