Skip to content

Commit

Permalink
Use daemon threads for background tasks in threading mode
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Sep 3, 2023
1 parent 48451a3 commit 541f172
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/engineio/async_drivers/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
_websocket_available = False


class DaemonThread(threading.Thread): # pragma: no cover
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs, daemon=True)


class WebSocketWSGI(object): # pragma: no cover
"""
This wrapper class provides a threading WebSocket interface that is
Expand Down Expand Up @@ -43,7 +48,7 @@ def wait(self):


_async = {
'thread': threading.Thread,
'thread': DaemonThread,
'queue': queue.Queue,
'queue_empty': queue.Empty,
'event': threading.Event,
Expand Down
7 changes: 3 additions & 4 deletions tests/common/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,10 @@ def test_async_mode_threading(self):
s = server.Server(async_mode='threading')
assert s.async_mode == 'threading'

import threading
from engineio.async_drivers import threading as async_threading
import queue

assert s._async['thread'] == threading.Thread
assert s._async['thread'] == async_threading.DaemonThread
assert s._async['queue'] == queue.Queue
assert s._async['websocket'] == async_threading.WebSocketWSGI
del sys.modules['simple_websocket']
Expand All @@ -115,10 +114,10 @@ def test_async_mode_threading_without_websocket(self):
s = server.Server(async_mode='threading')
assert s.async_mode == 'threading'

import threading
from engineio.async_drivers import threading as async_threading
import queue

assert s._async['thread'] == threading.Thread
assert s._async['thread'] == async_threading.DaemonThread
assert s._async['queue'] == queue.Queue
assert s._async['websocket'] is None
del sys.modules['engineio.async_drivers.threading']
Expand Down

0 comments on commit 541f172

Please sign in to comment.