twisted.internet.task.CooperativeTask(object) class documentationtwisted.internet.task
(View In Hierarchy)
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.
| See Also | Cooperator.cooperate | |
| Method | __init__ | A private constructor: to create a new CooperativeTask,
seeCooperator.cooperate. | 
| Method | whenDone | Get a defer.Deferrednotification of when this task is complete. | 
| Method | pause | No summary | 
| Method | resume | Resume processing of a paused CooperativeTask. | 
| Method | stop | Stop further processing of this task. | 
| Instance Variable | _iterator | the iterator to iterate when this CooperativeTaskis asked to do work. | 
| Instance Variable | _cooperator | the Cooperatorthat thisCooperativeTaskparticipates in, which is used to re-insert it upon resume. (type:Cooperator) | 
| Instance Variable | _deferreds | the list of defer.Deferreds
to fire when this task completes, fails, or finishes. (type:list) | 
| Instance Variable | _pauseCount | the number of times that this CooperativeTaskhas been paused; if 0, it is running. (type:int) | 
| Instance Variable | _completionState | The completion-state of this CooperativeTask.Noneif the task is not yet completed, an instance ofTaskStoppedifstopwas called to stop this task early, ofTaskFailedif
the application code in the iterator raised an exception which caused it to
terminate, and ofTaskDoneif it 
terminated normally via raisingStopIteration. (type:TaskFinished) | 
| Method | _completeWith | |
| Method | _checkFinish | If this task has been stopped, raise the appropriate subclass of TaskFinished. | 
| Method | _oneWorkUnit | Perform one unit of work for this task, retrieving one item from its 
iterator, stopping if there are no further items in the iterator, and 
pausing if the result was a defer.Deferred. | 
Cooperator 
that this CooperativeTask
participates in, which is used to re-insert it upon resume. (type: Cooperator)
  defer.Deferreds
to fire when this task completes, fails, or finishes. (type: list)
  CooperativeTask
has been paused; if 0, it is running. (type: int)
  CooperativeTask.
None
if the task is not yet completed, an instance of TaskStopped 
if stop was called to stop this task early, of TaskFailed if
the application code in the iterator raised an exception which caused it to
terminate, and of TaskDone if it 
terminated normally via raising StopIteration. (type: TaskFinished)
  A private constructor: to create a new CooperativeTask,
see Cooperator.cooperate.
Get a defer.Deferred
notification of when this task is complete.
| Returns | a defer.Deferredthat fires with theiteratorthat thisCooperativeTaskwas created with when the iterator has been exhausted (i.e. itsnextmethod has raisedStopIteration), or fails 
with the exception raised bynextif it raises some other 
exception. (type:defer.Deferred) | |
Pause this CooperativeTask.
Stop doing work until CooperativeTask.resume
is called.  If pause is called more than once, 
resume must be called an equal number of times to resume this 
task.
| Raises | TaskFinished | if this task has already finished or completed. | 
Resume processing of a paused CooperativeTask.
| Raises | NotPaused | if this CooperativeTaskis not paused. | 
| Parameters | completionState | a TaskFinishedexception or a subclass thereof, indicating what exception should be raised
when subsequent operations are performed. | 
| deferredResult | the result to fire all the deferreds with. | 
Stop further processing of this task.
| Raises | TaskFinished | if this CooperativeTaskhas previously completed, viastop, completion, or failure. | 
If this task has been stopped, raise the appropriate subclass of TaskFinished.
Perform one unit of work for this task, retrieving one item from its 
iterator, stopping if there are no further items in the iterator, and 
pausing if the result was a defer.Deferred.