teejusb / fsr

FSR code used for dance pads
GNU General Public License v3.0
62 stars 43 forks source link

Exit read, write threads on web server shutdown #30

Closed joshhead closed 2 years ago

joshhead commented 2 years ago

Proposed fix for #29

I found several potential reasons why child threads were not exiting.

  1. thread_stop_event is read but never written
  2. queue.Queue.get called in blocking mode without a timeout, preventing write thread from exiting
  3. Web socket requests can restart threads. Not sure if this is strictly related, but it seems simpler to account for the threads if they are started once.
  4. asyncio.queue.get is called with no timeout in the websocket handler, preventing it from exiting (it seems)

See also these notes on aiohttp graceful shutdown: https://docs.aiohttp.org/en/v0.22.4/web.html#aiohttp-web-graceful-shutdown

Address the above with the following changes

Also

teejusb commented 2 years ago

Thanks for this and the documentation + opening issue. One very minor stylistic change and I'll merge!

teejusb commented 2 years ago

Thanks!