Part of twisted.internet View Source
Class | LoopingCall | Call a function repeatedly. |
Class | SchedulerError | No summary |
Class | SchedulerStopped | The operation could not complete because the scheduler was stopped in progress or was already stopped. |
Class | TaskFinished | The operation could not complete because the task was already completed, stopped, encountered an error or otherwise permanently stopped running. |
Class | TaskDone | The operation could not complete because the task was already completed. |
Class | TaskStopped | The operation could not complete because the task was stopped. |
Class | TaskFailed | The operation could not complete because the task died with an unhandled error. |
Class | NotPaused | This exception is raised when a task is resumed which was not previously paused. |
Class | CooperativeTask | A CooperativeTask
is a task object inside a Cooperator ,
which can be paused, resumed, and stopped. It can also have its completion
(or termination) monitored. |
Class | Cooperator | Cooperative task scheduler. |
Function | coiterate | Cooperatively iterate over the given iterator, dividing runtime between it and all other iterators which have been passed to this function and not yet exhausted. |
Function | cooperate | Start running the given iterator as a long-running cooperative task, by calling next() on it as a periodic timed event. |
Class | Clock | Provide a deterministic, easily-controlled implementation of IReactorTime.callLater .
This is commonly useful for writing deterministic unit tests for code which
schedules events using this API. |
Function | deferLater | Call the given function after a certain period of time has passed. |
Function | react | Call main and run the reactor until the Deferred it
returns fires. |
Class | _Timer | Undocumented |
Function | _defaultScheduler | Undocumented |
Parameters | iterator | the iterator to invoke. |
Returns | a Deferred that will fire when the iterator finishes. |
This is very useful if you have computationally expensive tasks that you
want to run without blocking the reactor. Just break each task up so that
it yields frequently, pass it in here and the global Cooperator
will make sure work is distributed between them without blocking longer
than a single iteration of a single task.
Parameters | iterator | the iterator to invoke. |
Returns | a CooperativeTask
object representing this task. |
Parameters | clock | The object which will be used to schedule the delayed call. (type: IReactorTime
provider) |
delay | The number of seconds to wait before calling the function. (type: float or int ) | |
callable | The object to call after the delay. | |
*args | The positional arguments to pass to callable . | |
**kw | The keyword arguments to pass to callable . | |
Returns | A deferred that fires with the result of the callable when the specified
time has elapsed. (type: defer.Deferred ) |
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 |