@@ -62,19 +62,23 @@ def kill(self):
6262 def shutdown (self , timeout , callback = None ):
6363 logger .debug ("background worker got shutdown request" )
6464 with self ._lock :
65- if not self .is_alive :
66- return
67- self ._queue .put_nowait (_TERMINATOR )
68- initial_timeout = min (0.1 , timeout )
69- if not self ._timed_queue_join (initial_timeout ):
70- pending = self ._queue .qsize ()
71- logger .debug ("%d event(s) pending on shutdown" , pending )
72- if callback is not None :
73- callback (pending , timeout )
74- self ._timed_queue_join (timeout - initial_timeout )
65+ if self .is_alive :
66+ self ._queue .put_nowait (_TERMINATOR )
67+ if timeout > 0.0 :
68+ self ._wait_shutdown (timeout , callback )
7569 self ._thread = None
70+ self ._thread_for_pid = None
7671 logger .debug ("background worker shut down" )
7772
73+ def _wait_shutdown (self , timeout , callback ):
74+ initial_timeout = min (0.1 , timeout )
75+ if not self ._timed_queue_join (initial_timeout ):
76+ pending = self ._queue .qsize ()
77+ logger .debug ("%d event(s) pending on shutdown" , pending )
78+ if callback is not None :
79+ callback (pending , timeout )
80+ self ._timed_queue_join (timeout - initial_timeout )
81+
7882 def submit (self , callback ):
7983 self ._ensure_thread ()
8084 self ._queue .put_nowait (callback )
0 commit comments