Skip to content

Commit

Permalink
add react change
Browse files Browse the repository at this point in the history
  • Loading branch information
altendky committed Mar 3, 2021
1 parent 6360101 commit 0896be2
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions src/twisted/internet/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,34 +878,30 @@ async def main(reactor, username, password):
"""
if _reactor is None:
from twisted.internet import reactor as _reactor
finished = defer.ensureDeferred(main(_reactor, *argv))
codes = [0]

stopping = []
_reactor.addSystemEventTrigger("before", "shutdown", stopping.append, True)
def runMain():
try:
finished = main(_reactor, *argv)
except BaseException as exc:
cbFinish(Failure(exc))
else:
finished.addBoth(cbFinish)

def stop(result, stopReactor):
if stopReactor:
try:
_reactor.stop()
except ReactorNotRunning:
pass
def cbFinish(result):
try:
_reactor.stop()
except ReactorNotRunning:
pass

if isinstance(result, Failure):
if result.check(SystemExit) is not None:
code = result.value.code
codes[0] = result.value.code
else:
log.err(result, "main function encountered error")
code = 1
codes[0] = code

def cbFinish(result):
if stopping:
stop(result, False)
else:
_reactor.callWhenRunning(stop, result, True)
codes[0] = 1

finished.addBoth(cbFinish)
_reactor.callWhenRunning(runMain)
_reactor.run()
sys.exit(codes[0])

Expand Down

0 comments on commit 0896be2

Please sign in to comment.