Skip to content

Instantly share code, notes, and snippets.

@adiroiban
Created April 23, 2013 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adiroiban/5442928 to your computer and use it in GitHub Desktop.
Save adiroiban/5442928 to your computer and use it in GitHub Desktop.
Reactor stop with exit code.
def _exit(self, exit_code=0):
"""
Helper method for testing.
Use os._exit() to avoid re-raising SystemExit error.
When reactor is running add a hook to be called after reactor stop.
This is mocked in tests since we can not addSystemEventTrigger
multiple times for the same reactor.
"""
def shutdown():
Logger.shutdown()
os._exit(exit_code)
if reactor.running:
reactor.addSystemEventTrigger(
'before', 'shutdown', self.stopServices)
reactor.addSystemEventTrigger('after', 'shutdown', shutdown)
reactor.stop()
else:
shutdown()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment