-
Notifications
You must be signed in to change notification settings - Fork 189
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
Ctrl+C Cancel clean up issue #179
Comments
For more info, the actual client seems to be correctly transitioning to a closed state through these messages:
|
Figured out why this was happening, not sure if it's a bug or expected behavior in HBMQTT: My program uses an EventLoop, but it exists in a different thread than the one I've been instantiating my MQTTClient in. While I do pass this loop in to the MQTTClient, the thread context doesn't actually have a loop, so calling The path that this happens through is in https://github.com/beerfactory/hbmqtt/blob/master/hbmqtt/client.py#L116, because the PluginManager (https://github.com/beerfactory/hbmqtt/blob/master/hbmqtt/plugins/manager.py#L43) isn't getting passed the loop that I provided to the Client. In theory, shouldn't the PluginManager inherit the same loop that the Client created / was given? |
Just realized that there's an open PR to address this exact thing #126 ... |
Another solution would be to use #178. |
I've been struggling to figure out how to clean up my close logic on a while loop using this client. Using Python 3.5.6, installed
hbmqtt
locally from a cloned master branch (pip install -e hbmqtt
), but the same issue plagued me on 0.9.5.In my code, I create a client connection with
My main loop is essentially a while loop with a handler for KeyboardInterrupts and a task canceller, which eventually throws me to the stop() function designed to stop all of my running tasks before the event loop closes (using the cancel code from the last comment in #94 , but I have the same type of cancel logic elsewhere):
However, this isn't actually cancelling all of my tasks. After
stop()
completes, and my EventLoop closes down, I get multiple warnings that there were additional pending tasks that failed to cancel:There are generally multiple of these (like, a minimum of 3), even if I don't do anything other than connect and disconnect (I commented out every subscription and publish to try and get a basic idle unconfigured client).
For some reason it doesn't seem like these tasks are part of the list of tasks when the cancel process is happening, but I'm not sure how to stop them from getting created before running my "cancel everything" routine (I was trying the sleep after disconnect, but that doesn't seem to be achieving my desired result).
Any ideas on what I'm doing wrong?
The text was updated successfully, but these errors were encountered: