Commit 7e7f5678 authored by Vincent Pelletier's avatar Vincent Pelletier

CMFActivity.ActivityTool: Use context managers for locking.

Not all lock uses in this code fit context managers, but use them where it
does.
parent c724f2b0
...@@ -1300,14 +1300,12 @@ class ActivityTool (BaseTool): ...@@ -1300,14 +1300,12 @@ class ActivityTool (BaseTool):
# return if the number of threads is too high # return if the number of threads is too high
# else, increase the number of active_threads and continue # else, increase the number of active_threads and continue
tic_lock.acquire() with tic_lock:
too_many_threads = (active_threads >= max_active_threads) too_many_threads = (active_threads >= max_active_threads)
if not too_many_threads or force: if not too_many_threads or force:
active_threads += 1 active_threads += 1
else: else:
tic_lock.release()
raise RuntimeError, 'Too many threads' raise RuntimeError, 'Too many threads'
tic_lock.release()
inner_self = aq_inner(self) inner_self = aq_inner(self)
...@@ -1338,9 +1336,8 @@ class ActivityTool (BaseTool): ...@@ -1338,9 +1336,8 @@ class ActivityTool (BaseTool):
is_running_lock.release() is_running_lock.release()
finally: finally:
# decrease the number of active_threads # decrease the number of active_threads
tic_lock.acquire() with tic_lock:
active_threads -= 1 active_threads -= 1
tic_lock.release()
def hasActivity(self, *args, **kw): def hasActivity(self, *args, **kw):
# Check in each queue if the object has deferred tasks # Check in each queue if the object has deferred tasks
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment