do not return None to user's greenlet, but raise an exception if reactor.stop() was called

This commit is contained in:
Denis Bilenko
2008-10-10 16:18:05 +07:00
parent ed6ae02c6c
commit 2de3aaac51

View File

@@ -72,15 +72,26 @@ class Hub:
if Hub.state == 1: if Hub.state == 1:
reactor.startRunning(installSignalHandlers=installSignalHandlers) 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: try:
self.mainLoop(reactor) self.mainLoop(reactor)
#except: except:
# sys.stderr.write('\nexception in mainloop\n') # an exception in the mainLoop is a normal operation (e.g. user's
# traceback.print_exc() # signal handler could raise an exception). In this case we will re-enter
# raise # the main loop at the next switch.
finally:
Hub.state = 3 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): def mainLoop(self, reactor):
Hub.state = 2 Hub.state = 2