Use with statement for _job_manager_lock.

This commit is contained in:
Ethan Dalool 2020-02-12 19:16:35 -08:00
parent f6872e77cf
commit 64d0968040

View file

@ -97,8 +97,8 @@ class ThreadPool:
a human friendly name string.
'''
self.assert_not_closed()
self._job_manager_lock.acquire()
with self._job_manager_lock:
job = Job(
pool=self,
function=function,
@ -111,7 +111,6 @@ class ThreadPool:
if not self.paused:
self._clear_done_and_start_jobs()
self._job_manager_lock.release()
return job
def add_many(self, kwargss):
@ -127,8 +126,8 @@ class ThreadPool:
]
'''
self.assert_not_closed()
self._job_manager_lock.acquire()
with self._job_manager_lock:
these_jobs = []
for kwargs in kwargss:
kwargs.pop('pool', None)
@ -139,7 +138,6 @@ class ThreadPool:
if not self.paused:
self._clear_done_and_start_jobs()
self._job_manager_lock.release()
return these_jobs
def clear_done_and_start_jobs(self):
@ -154,10 +152,9 @@ class ThreadPool:
Because the pool's internal job queue is flushed regularly, you should
store your own references to jobs to get their return values.
'''
self._job_manager_lock.acquire()
with self._job_manager_lock:
self._clear_done_and_start_jobs()
self.paused = False
self._job_manager_lock.release()
def join(self):
'''