Commit 8b7843cd authored by Jean-Paul Smets's avatar Jean-Paul Smets

update locking system


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@324 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b68ad228
...@@ -42,6 +42,7 @@ from zLOG import LOG ...@@ -42,6 +42,7 @@ from zLOG import LOG
active_threads = 0 active_threads = 0
max_active_threads = 1 # 2 will cause more bug to appear (he he) max_active_threads = 1 # 2 will cause more bug to appear (he he)
is_initialized = 0 is_initialized = 0
tic_lock = threading.Lock() # A RAM based lock
# Activity Registration # Activity Registration
activity_dict = {} activity_dict = {}
...@@ -129,7 +130,6 @@ class ActivityTool (Folder, UniqueObject): ...@@ -129,7 +130,6 @@ class ActivityTool (Folder, UniqueObject):
meta_type = 'CMF Activity Tool' meta_type = 'CMF Activity Tool'
allowed_types = ( 'CMF Active Process', ) allowed_types = ( 'CMF Active Process', )
security = ClassSecurityInfo() security = ClassSecurityInfo()
tic_lock = threading.Lock()
manage_options = tuple( manage_options = tuple(
[ { 'label' : 'Overview', 'action' : 'manage_overview' } [ { 'label' : 'Overview', 'action' : 'manage_overview' }
...@@ -190,19 +190,19 @@ class ActivityTool (Folder, UniqueObject): ...@@ -190,19 +190,19 @@ class ActivityTool (Folder, UniqueObject):
global active_threads, is_initialized global active_threads, is_initialized
# return if the number of threads is too high # return if the number of threads is too high
if active_threads > max_active_threads: if active_threads >= max_active_threads:
if not force: return 'Too many threads' if not force: return 'Too many threads'
if self.tic_lock is None: if tic_lock is None:
return return
# Initialize if needed # Initialize if needed
if not is_initialized: self.initialize() if not is_initialized: self.initialize()
# increase the number of active_threads # increase the number of active_threads
self.tic_lock.acquire() tic_lock.acquire()
active_threads += 1 active_threads += 1
self.tic_lock.release() tic_lock.release()
# Wakeup each queue # Wakeup each queue
for activity in activity_list: for activity in activity_list:
...@@ -225,9 +225,9 @@ class ActivityTool (Folder, UniqueObject): ...@@ -225,9 +225,9 @@ class ActivityTool (Folder, UniqueObject):
LOG('CMFActivity:', 100, 'Core call to tic or isAwake failed for activity %s' % activity) LOG('CMFActivity:', 100, 'Core call to tic or isAwake failed for activity %s' % activity)
# decrease the number of active_threads # decrease the number of active_threads
self.tic_lock.acquire() tic_lock.acquire()
active_threads -= 1 active_threads -= 1
self.tic_lock.release() tic_lock.release()
def hasActivity(self, object, **kw): def hasActivity(self, object, **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