Commit 30221b0 1 parent 31c9ce3 commit 30221b0 Copy full SHA for 30221b0
File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change 2
2
# -*- coding: utf-8 -*-
3
3
# vim: ai ts=4 sts=4 et sw=4 nu
4
4
5
+ import datetime
5
6
import queue
6
7
import threading
7
8
from typing import Callable
12
13
# Lock that ensures that new workers are not created while the interpreter is
13
14
# shutting down. Must be held while mutating _threads_queues and _shutdown.
14
15
_global_shutdown_lock = threading .Lock ()
16
+ thread_deadline_sec = 60
15
17
16
18
17
19
def excepthook (args ):
@@ -129,11 +131,19 @@ def join(self):
129
131
"""Await completion of workers, requesting them to stop taking new task"""
130
132
logger .debug (f"joining all threads for { self .prefix } " )
131
133
self .no_more = True
132
- for t in self ._workers :
134
+ for num , t in enumerate (self ._workers ):
135
+ deadline = datetime .datetime .now () + datetime .timedelta (
136
+ seconds = thread_deadline_sec
137
+ )
138
+ logger .debug (f"Giving { self .prefix } { num } { thread_deadline_sec } s to join" )
133
139
e = threading .Event ()
134
- while t .is_alive ():
140
+ while t .is_alive () and datetime . datetime . now () < deadline :
135
141
t .join (1 )
136
142
e .wait (timeout = 2 )
143
+ if t .is_alive ():
144
+ logger .debug (f"Thread { self .prefix } { num } is not joining. Skipping…" )
145
+ else :
146
+ logger .debug (f"Thread { self .prefix } { num } joined" )
137
147
logger .debug (f"all threads joined for { self .prefix } " )
138
148
139
149
def release_halt (self ):
You can’t perform that action at this time.
0 commit comments