@@ -62,19 +62,23 @@ def kill(self):
62
62
def shutdown (self , timeout , callback = None ):
63
63
logger .debug ("background worker got shutdown request" )
64
64
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 )
75
69
self ._thread = None
70
+ self ._thread_for_pid = None
76
71
logger .debug ("background worker shut down" )
77
72
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
+
78
82
def submit (self , callback ):
79
83
self ._ensure_thread ()
80
84
self ._queue .put_nowait (callback )
0 commit comments