python - Unit of work is driven by external event. How to ensure one unit starts only after the previous one ends? -


i not sure how refactor app. have read chaineddefered, lost @ how apply technique situation. pointer/suggestions welcome.

i using third party library monitor external data source changes rapidly in real time. whenever change detected, library call callback function in code. callback function in turn retrieve data database , perform processing.

class myapp(object):     def start(self):         in range(1, 1000):             mycallback = callbackhandler(x, y, z)             thirdpartylib.subscribe(event_name + str(i), mycallback)       reactor.start()   class callbackhandler(object):     def __init__(self, x, y, z):          ....      def getsomedataanddosomething(self):         ...      def __call__(self)        calllater(self.getsomedataanddosomething) 

the problem callbackhandler can called consecutively numerous times when events happen rapidly in short interval. if these callbacks executed more or less simultaneously, produce identical result.

how can fire callback iff last callback has finished processing? i'd prefer use constructs offered in twisted achieve instead of, says, comparing timestamps of events (so drop callback if has been fired 1 sec before) or global variable flag.

in future, please include complete code samples.

if want execute deferred-returning limited level of concurrency, twisted includes class called deferredsemaphore can use.

in 2006, jean-paul calderone wrote great blog post how limit parallelism it.


Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -