예제 #1
0
 def __init__(self):
     self.starting_event = Event()   # used to lock task until _work() is called
     self.running_event = Event()    # used to lock running loop
     self.finished_event = Event()   # used to lock until Task.work() is complete
     self.failsafe = None
     self.data = None
     Task.__init__(self)
예제 #2
0
    def work(self, args={}, callback=None, callback_args={}):
        """
        extended to add locks at the end of the work
        """
        try:
            # set a failsafe to ensure events get cleared
            self.failsafe = reactor.callLater(5, self.clear_events)

            ret = Task.work(self, args, callback, callback_args)
            self.finished_event.set()

        finally:
            if self.failsafe:
                self.failsafe.cancel()

        return ret