Esempio n. 1
0
 def __init__(self, interval):
     self._monitors = {}
     self._interval = interval
     # NOTE: This must be used in asynchronous mode to prevent blocking of
     # the checker event loop thread.
     self.onDomainStateChange = misc.Event(
         "Storage.DomainMonitor.onDomainStateChange", sync=False)
     self._checker = check.CheckService()
     self._checker.start()
Esempio n. 2
0
 def testInstanceMethod(self):
     ev = threading.Event()
     event = misc.Event("name", sync=True)
     receiver = Receiver(event, ev)
     print(event._registrar)
     event.emit()
     ev.wait(TIMEOUT)
     self.assertTrue(ev.isSet())
     receiver  # Makes pyflakes happy
Esempio n. 3
0
 def testUnregister(self):
     ev = threading.Event()
     callback = lambda: ev.set()
     event = misc.Event("EndOfTheWorld")
     event.register(callback)
     event.unregister(callback)
     event.emit()
     ev.wait(TIMEOUT)
     self.assertFalse(ev.isSet())
Esempio n. 4
0
 def testEmitStale(self):
     ev = threading.Event()
     callback = lambda: ev.set()
     event = misc.Event("EndOfTheWorld")
     event.register(callback)
     del callback
     event.emit()
     ev.wait(5)
     self.assertFalse(ev.isSet())
Esempio n. 5
0
 def testInstanceMethodDead(self):
     ev = threading.Event()
     event = misc.Event("name", sync=True)
     receiver = Receiver(event, ev)
     print(event._registrar)
     del receiver
     print(event._registrar)
     event.emit()
     ev.wait(TIMEOUT)
     self.assertFalse(ev.isSet())
Esempio n. 6
0
    def testEmit(self):
        ev = threading.Event()

        def callback():
            self.log.info("Callback called")
            ev.set()

        event = misc.Event("EndOfTheWorld")
        event.register(callback)
        event.emit()
        ev.wait(TIMEOUT)
        self.assertTrue(ev.isSet())
Esempio n. 7
0
    def testEmitCallbackException(self):
        ev = threading.Event()

        def callback1():
            raise Exception("AHHHHHHH!!!")

        def callback2():
            ev.set()

        event = misc.Event("EndOfTheWorld", sync=True)
        event.register(callback1)
        event.register(callback2)
        event.emit()
        ev.wait(TIMEOUT)
        self.assertTrue(ev.isSet())
Esempio n. 8
0
    def testOneShot(self):
        ev = threading.Event()

        def callback():
            self.log.info("Callback called")
            ev.set()

        event = misc.Event("EndOfTheWorld")
        event.register(callback, oneshot=True)
        event.emit()
        ev.wait(TIMEOUT)
        self.assertTrue(ev.isSet())
        ev.clear()
        event.emit()
        ev.wait(TIMEOUT)
        self.assertFalse(ev.isSet())