File tree 2 files changed +10
-2
lines changed
2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -82,8 +82,13 @@ def __init__(
82
82
# Mapping of ping IDs to pong waiters, in chronological order.
83
83
self .ping_waiters : Dict [bytes , threading .Event ] = {}
84
84
85
- # Receiving events from the socket.
86
- self .recv_events_thread = threading .Thread (target = self .recv_events )
85
+ # Receiving events from the socket. This thread explicitly is marked as
86
+ # to support creating a connection in a non-daemon thread then using it
87
+ # in a daemon thread; this shouldn't block the intpreter from exiting.
88
+ self .recv_events_thread = threading .Thread (
89
+ target = self .recv_events ,
90
+ daemon = True ,
91
+ )
87
92
self .recv_events_thread .start ()
88
93
89
94
# Exception raised in recv_events, to be chained to ConnectionClosed
Original file line number Diff line number Diff line change @@ -233,6 +233,9 @@ def serve_forever(self) -> None:
233
233
sock , addr = self .socket .accept ()
234
234
except OSError :
235
235
break
236
+ # Since there isn't a mechanism for tracking connections and waiting
237
+ # for them to terminate, we cannot use daemon threads, or else all
238
+ # connections would be terminate brutally when closing the server.
236
239
thread = threading .Thread (target = self .handler , args = (sock , addr ))
237
240
thread .start ()
238
241
You can’t perform that action at this time.
0 commit comments