When I had a need for returning an exit status from a Twisted process, my first instinct was to look for a reactor.stop
argument. In fact, there have been multiple requests for such, e.g. tickets #718 and #2182. But, then, I realized that reactor.stop
doesn't stop the reactor, it merely initiates the shutdown process. The reactor is not shut down until reactor.run
exits. This realization made it clear what I should do to return a specific exit code---simply add
sys.exit(code)
immediately after reactor.run
.