Move nested function do_it out to _run.

This commit is contained in:
Ethan Dalool 2020-10-06 23:09:06 -07:00
parent 0202aeaca0
commit 5147d7b988

View file

@ -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()