Skip to content

Commit 2afadf7

Browse files
committed
small change in case the target thread has exited, but is_alive is not set to false yet
1 parent 29ee9e8 commit 2afadf7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/prpy/util.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,12 @@ def reset(self):
529529
Also restarts the timer thread if it has existed
530530
'''
531531
with self.timer_thread_lock:
532+
if self.canceled or not self.thread_checking_time.is_alive():
533+
self.thread_checking_time = threading.Thread(target=self._check_timer_loop)
534+
self.thread_checking_time.start()
535+
532536
self.start_time = time.time()
533537
self.canceled = False
534-
if not self.thread_checking_time.is_alive():
535-
self.thread_checking_time = threading.Thread(target=self._check_timer_loop)
536-
self.thread_checking_time.start()
537538

538539
def stop(self):
539540
'''
@@ -556,7 +557,8 @@ def _check_timer_loop(self):
556557
elapsed_time = time.time() - self.start_time
557558
if elapsed_time > self.timeout_duration:
558559
self.handler(*self.handler_args, **self.handler_kwargs)
559-
self.canceled = True
560+
with self.timer_thread_lock:
561+
self.canceled = True
560562
break
561563
else:
562564
time.sleep(self.timeout_duration - elapsed_time)

0 commit comments

Comments
 (0)