def stop_reactor(exit_code=0):
'''
Stop the reactor and exit with exit_code.
If exit_code is None, don't exit, just return to the caller.
exit_code must be between 1 and 255.
'''
if exit_code is not None:
logging.warning("Exiting with code {}".format(exit_code))
else:
# Let's hope the calling code exits pretty soon after this
logging.warning("Stopping reactor")
try:
reactor.stop()
except ReactorNotRunning:
pass
# return to the caller and let it decide what to do
if exit_code == None:
return
# a graceful exit
if exit_code == 0:
sys.exit()
# a hard exit
assert exit_code >= 0
assert exit_code <= 127
os._exit(exit_code)
评论列表
文章目录