twisted.internet.task.react(main, argv=(), _reactor=None) function documentationtwisted.internet.task
View Source
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 reactor.run
directly, as this function will also:
reactor.stop once and only once, and at
the right time.
Deferred returned by
main.
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'))
| Parameters | main | A callable which returns a Deferred. It
should take the reactor as its first parameter, followed by the elements of
argv. |
| argv | A list of arguments to pass to main. If omitted the callable
will be invoked with no additional arguments. | |
| _reactor | An implementation detail to allow easier unit testing. Do not supply this parameter. | |
| Present Since | 12.3 | |