From 5147d7b9889b8979049cfcc6c7a847c68c878b62 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 6 Oct 2020 23:09:06 -0700 Subject: [PATCH] Move nested function do_it out to _run. --- voussoirkit/threadpool.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/voussoirkit/threadpool.py b/voussoirkit/threadpool.py index 2dfa543..1ca4daa 100644 --- a/voussoirkit/threadpool.py +++ b/voussoirkit/threadpool.py @@ -199,6 +199,17 @@ class Job: else: return f'<{self.status} Job on {self.function}>' + def _run(self): + try: + self.value = self.function(*self.args, **self.kwargs) + self.status = FINISHED + except Exception as exc: + self.exception = exc + self.status = RAISED + self._thread = None + self.pool._job_finished() + self._joinme_lock.release() + def join(self): ''' Block until this job runs and completes. @@ -212,18 +223,7 @@ class Job: return value in `value`. If it raises an exception, you'll find it in `exception`, although the thread itself will not raise. ''' - def do_it(): - try: - self.value = self.function(*self.args, **self.kwargs) - self.status = FINISHED - except Exception as 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 = threading.Thread(target=self._run) self._thread.daemon = True self._thread.start()