Call main and run the reactor until the Deferred it returns fires.

This is intended as the way to start up an application with a well-defined completion condition. Use it to write clients or one-off asynchronous operations. Prefer this to calling directly, as this function will also:

  • Take care to call reactor.stop once and only once, and at the right time.
  • Log any failures from the Deferred returned by main.
  • Exit the application when done, with exit code 0 in case of success and 1 in case of failure. If main fails with a SystemExit error, the code returned is used.

The following demonstrates the signature of a main function which can be used with react:

     def main(reactor, username, password):
         return defer.succeed('ok')

     task.react(main, ('alice', 'secret'))
ParametersmainA callable which returns a Deferred. It should take the reactor as its first parameter, followed by the elements of argv.
argvA list of arguments to pass to main. If omitted the callable will be invoked with no additional arguments.
_reactorAn implementation detail to allow easier unit testing. Do not supply this parameter.
Present Since12.3
API Documentation for Twisted, generated by pydoctor at 2015-05-24 20:04:00.