I'm developing a plugin to implement some voice commands in OctoPrint. The plugin spin up a pyaudio stream (thread?) that continuously receives audio frames from a USB microphone.
The plugin works well, meaning it can run in parallel to the other tasks OctoPrint needs to do, is non-blocking and requires minimal resources.
However it doesn't stop gracefully for some reason and every other reboot OctoPrint start in safe mode with the plugin disabled. Rebooting from safe mode then brings the plugin back, and reboting again the cycle repeats itself.
During development, when OctoPrint is started manually from command line:
- sending Ctrl+C has no apparent effect (well not in the logging at least)
- sending Ctrl+C second time will terminate octoprint with an exception
In the on_shutdown hook of the plugin I call a method to "destroy" the audio stream and everything linked to it, which will eventually doesn't complete and stays hanging
Is there another way to terminate running threads inside a plugin?
I might be missing some fundamental aspect of the OctoPrint architecture here