Ordered events

This commit is contained in:
Ruud committed 2012-02-11 14:02:34 +01:00
1 parent fd485a702e
commit 79ad9e3e2e
3 files changed
+18 -4

No files matched your search

+10 -2
View File
@@ -66,11 +66,19 @@ def fireEvent(name, *args, **kwargs):
merge = True merge = True
except: pass except: pass
# Merge items
in_order = False
try:
del kwargs['in_order']
in_order = True
except: pass
e = events[name] e = events[name]
e.lock.acquire() if not in_order: e.lock.acquire()
e.asynchronous = False e.asynchronous = False
e.in_order = in_order
result = e(*args, **kwargs) result = e(*args, **kwargs)
e.lock.release() if not in_order: e.lock.release()
if single and not merge: if single and not merge:
results = None results = None
+1 -1
View File
@@ -161,7 +161,7 @@ def runCouchPotato(options, base_path, args, desktop = None):
setup() setup()
if initialize: if initialize:
fireEvent('app.initialize') fireEvent('app.initialize', in_order = True)
fire_load = True fire_load = True
+7 -1
View File
@@ -16,7 +16,6 @@ import Queue
import hashlib import hashlib
import sys import sys
import threading import threading
import time
class Event(object): class Event(object):
""" """
@@ -96,6 +95,7 @@ class Event(object):
(None, None, handler), ... # asynchronous execution (None, None, handler), ... # asynchronous execution
) )
""" """
self.in_order = False
self.asynchronous = asynch self.asynchronous = asynch
self.exc_info = exc_info self.exc_info = exc_info
self.lock = lock self.lock = lock
@@ -181,6 +181,9 @@ class Event(object):
h_ = self.queue.get() h_ = self.queue.get()
handler, memoize, timeout = self.handlers[h_] handler, memoize, timeout = self.handlers[h_]
if self.lock and self.in_order:
self.lock.acquire()
try: try:
r = self._memoize(memoize, timeout, handler, *args, **kwargs) r = self._memoize(memoize, timeout, handler, *args, **kwargs)
if not self.asynchronous: if not self.asynchronous:
@@ -197,6 +200,9 @@ class Event(object):
if not self.asynchronous: if not self.asynchronous:
self.queue.task_done() self.queue.task_done()
if self.lock and self.in_order:
self.lock.release()
if self.queue.empty(): if self.queue.empty():
raise Queue.Empty raise Queue.Empty