From 2de3aaac51c3006361e4d42a67a2e73c8c9e948c Mon Sep 17 00:00:00 2001 From: Denis Bilenko Date: Fri, 10 Oct 2008 16:18:05 +0700 Subject: [PATCH] do not return None to user's greenlet, but raise an exception if reactor.stop() was called --- eventlet/hubs/twistedreactor.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/eventlet/hubs/twistedreactor.py b/eventlet/hubs/twistedreactor.py index 5f80ee7..da503a9 100644 --- a/eventlet/hubs/twistedreactor.py +++ b/eventlet/hubs/twistedreactor.py @@ -72,15 +72,26 @@ class Hub: if Hub.state == 1: reactor.startRunning(installSignalHandlers=installSignalHandlers) + elif not reactor.running: + # if we're here, then reactor was explicitly stopped with reactor.stop() + # restarting reactor (like we would do after an exception) in this case + # is not an option. + raise AssertionError("reactor is not running") try: self.mainLoop(reactor) - #except: - # sys.stderr.write('\nexception in mainloop\n') - # traceback.print_exc() - # raise - finally: + except: + # an exception in the mainLoop is a normal operation (e.g. user's + # signal handler could raise an exception). In this case we will re-enter + # the main loop at the next switch. Hub.state = 3 + raise + + # if we have twisted's signal handlers installed and mainLoop has just exited, + # we must report the error to the user's greenlet. + # QQQ actually we raise this error in all the user's greenlets, to let them + # clean properly. never executing them again is cruel (unless they're daemons) + raise AssertionError("reactor was stopped") def mainLoop(self, reactor): Hub.state = 2