From 7de2833df9c22a2de6ef815241e53771a3b8dd4a Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 12 Feb 2020 17:30:23 -0800 Subject: [PATCH] Make the job's thread private and toss it after it's done. --- voussoirkit/threadpool.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/voussoirkit/threadpool.py b/voussoirkit/threadpool.py index 1bbf395..e83a8ac 100644 --- a/voussoirkit/threadpool.py +++ b/voussoirkit/threadpool.py @@ -157,7 +157,7 @@ class Job: self.kwargs = kwargs self.value = NO_RETURN self.exception = NO_EXCEPTION - self.thread = None + self._thread = None # joinme_lock works because it is possible for a single thread to block # itself by calling `lock.acquire()` twice. The first call is here, @@ -193,10 +193,11 @@ class Job: # print(exc) self.exception = exc self.status = RAISED + self._thread = None self.pool._job_finished() self.joinme_lock.release() self.status = RUNNING - self.thread = threading.Thread(target=do_it) - self.thread.daemon = True - self.thread.start() + self._thread = threading.Thread(target=do_it) + self._thread.daemon = True + self._thread.start()