def runReactor(self, app, reactor): """ Register the app, run the reactor, make sure app was activated, and that reactor was running, and that reactor can be stopped. """ if not hasattr(app, "quit"): raise SkipTest("Version of PyGObject is too old.") result = [] def stop(): result.append("stopped") reactor.stop() def activate(widget): result.append("activated") reactor.callLater(0, stop) app.connect("activate", activate) # We want reactor.stop() to *always* stop the event loop, even if # someone has called hold() on the application and never done the # corresponding release() -- for more details see # http://developer.gnome.org/gio/unstable/GApplication.html. app.hold() reactor.registerGApplication(app) ReactorBuilder.runReactor(self, reactor) self.assertEqual(result, ["activated", "stopped"])
def runReactor(self, app, reactor): """ Register the app, run the reactor, make sure app was activated, and that reactor was running, and that reactor can be stopped. """ if not hasattr(app, "quit"): raise SkipTest("Version of PyGObject is too old.") result = [] def stop(): result.append("stopped") reactor.stop() def activate(widget): result.append("activated") reactor.callLater(0, stop) app.connect('activate', activate) # We want reactor.stop() to *always* stop the event loop, even if # someone has called hold() on the application and never done the # corresponding release() -- for more details see # http://developer.gnome.org/gio/unstable/GApplication.html. app.hold() reactor.registerGApplication(app) ReactorBuilder.runReactor(self, reactor) self.assertEqual(result, ["activated", "stopped"])
def test_cantRegisterAfterRun(self): """ It is not possible to register a C{Application} after the reactor has already started. """ reactor = gireactor.GIReactor(useGtk=False) self.addCleanup(self.unbuildReactor, reactor) app = Gio.Application(application_id="com.twistedmatrix.trial.gireactor", flags=Gio.ApplicationFlags.FLAGS_NONE) def tryRegister(): exc = self.assertRaises(ReactorAlreadyRunning, reactor.registerGApplication, app) self.assertEqual(exc.args[0], "Can't register application after reactor was started.") reactor.stop() reactor.callLater(0, tryRegister) ReactorBuilder.runReactor(self, reactor)
def buildReactor(self): reactor = ReactorBuilder.buildReactor(self) from twisted.internet import _producer_helpers # Patch twisted.protocols.tls to use this reactor, until we get # around to fixing #5206, or the TLS code uses an explicit reactor: cooperator = Cooperator(scheduler=lambda x: reactor.callLater(0.00001, x)) self.patch(_producer_helpers, "cooperate", cooperator.cooperate) return reactor
def test_cantRegisterAfterRun(self): """ It is not possible to register a C{Application} after the reactor has already started. """ reactor = gireactor.GIReactor(useGtk=False) self.addCleanup(self.unbuildReactor, reactor) app = Gio.Application( application_id='com.twistedmatrix.trial.gireactor', flags=Gio.ApplicationFlags.FLAGS_NONE) def tryRegister(): exc = self.assertRaises(ReactorAlreadyRunning, reactor.registerGApplication, app) self.assertEqual(exc.args[0], "Can't register application after reactor was started.") reactor.stop() reactor.callLater(0, tryRegister) ReactorBuilder.runReactor(self, reactor)
def buildReactor(self): reactor = ReactorBuilder.buildReactor(self) from twisted.internet import _producer_helpers # Patch twisted.protocols.tls to use this reactor, until we get # around to fixing #5206, or the TLS code uses an explicit reactor: cooperator = Cooperator( scheduler=lambda x: reactor.callLater(0.00001, x)) self.patch(_producer_helpers, "cooperate", cooperator.cooperate) return reactor
def buildReactor(self): reactor = ReactorBuilder.buildReactor(self) try: from twisted.protocols import tls except ImportError: return reactor # Patch twisted.protocols.tls to use this reactor, until we get # around to fixing #5206, or the TLS code uses an explicit reactor: cooperator = Cooperator( scheduler=lambda x: reactor.callLater(0.00001, x)) self.patch(tls, "cooperate", cooperator.cooperate) return reactor