Use with statement for _job_manager_lock.
This commit is contained in:
parent
f6872e77cf
commit
64d0968040
1 changed files with 23 additions and 26 deletions
|
@ -97,8 +97,8 @@ class ThreadPool:
|
||||||
a human friendly name string.
|
a human friendly name string.
|
||||||
'''
|
'''
|
||||||
self.assert_not_closed()
|
self.assert_not_closed()
|
||||||
self._job_manager_lock.acquire()
|
|
||||||
|
|
||||||
|
with self._job_manager_lock:
|
||||||
job = Job(
|
job = Job(
|
||||||
pool=self,
|
pool=self,
|
||||||
function=function,
|
function=function,
|
||||||
|
@ -111,7 +111,6 @@ class ThreadPool:
|
||||||
if not self.paused:
|
if not self.paused:
|
||||||
self._clear_done_and_start_jobs()
|
self._clear_done_and_start_jobs()
|
||||||
|
|
||||||
self._job_manager_lock.release()
|
|
||||||
return job
|
return job
|
||||||
|
|
||||||
def add_many(self, kwargss):
|
def add_many(self, kwargss):
|
||||||
|
@ -127,8 +126,8 @@ class ThreadPool:
|
||||||
]
|
]
|
||||||
'''
|
'''
|
||||||
self.assert_not_closed()
|
self.assert_not_closed()
|
||||||
self._job_manager_lock.acquire()
|
|
||||||
|
|
||||||
|
with self._job_manager_lock:
|
||||||
these_jobs = []
|
these_jobs = []
|
||||||
for kwargs in kwargss:
|
for kwargs in kwargss:
|
||||||
kwargs.pop('pool', None)
|
kwargs.pop('pool', None)
|
||||||
|
@ -139,7 +138,6 @@ class ThreadPool:
|
||||||
if not self.paused:
|
if not self.paused:
|
||||||
self._clear_done_and_start_jobs()
|
self._clear_done_and_start_jobs()
|
||||||
|
|
||||||
self._job_manager_lock.release()
|
|
||||||
return these_jobs
|
return these_jobs
|
||||||
|
|
||||||
def clear_done_and_start_jobs(self):
|
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
|
Because the pool's internal job queue is flushed regularly, you should
|
||||||
store your own references to jobs to get their return values.
|
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._clear_done_and_start_jobs()
|
||||||
self.paused = False
|
self.paused = False
|
||||||
self._job_manager_lock.release()
|
|
||||||
|
|
||||||
def join(self):
|
def join(self):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in a new issue