Created
April 23, 2013 11:44
-
-
Save adiroiban/5442928 to your computer and use it in GitHub Desktop.
Reactor stop with exit code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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