Constructor

Class: cogen.core.coroutines.Coroutine

We need a coroutine wrapper for generators and function alike because we want to run functions that don't return generators just like a coroutine.

Constructor

__init__ (self, coro, *args, **kws)

Methods

add_waiter (self, coro)

finalize (self)

handle_error (self)

process (self, sched, coro)

remove_waiter (self, coro)

run_op (self, op)

Handle the operation:

  • if coro is in STATE_RUNNING, send or throw the given op

  • if coro is in STATE_NEED_INIT, call the init function and if it doesn't return a generator, set STATE_COMPLETED and set the result to whatever the function returned. * if StopIteration is raised, set STATE_COMPLETED and return self. * if any other exception is raised, set STATE_FAILED, handle error

    System Message: ERROR/3 (<string>, line 9)

    Unexpected indentation.

    or send it to the caller, return self

Return self is used as a optimization. Coroutine is also a Operation which handles it's own completion (resuming the caller and the waiters).

Attributes

STATE_COMPLETED

Value of STATE_COMPLETED

2

STATE_FAILED

Value of STATE_FAILED

3

STATE_FINALIZED

Value of STATE_FINALIZED

4

STATE_NEED_INIT

Value of STATE_NEED_INIT

0

STATE_RUNNING

Value of STATE_RUNNING

1

caller

Value of caller

<member 'caller' of 'Coroutine' objects>

coro

Value of coro

<member 'coro' of 'Coroutine' objects>

debug

Value of debug

<member 'debug' of 'Coroutine' objects>

exception

Value of exception

<member 'exception' of 'Coroutine' objects>

f_args

Value of f_args

<member 'f_args' of 'Coroutine' objects>

f_kws

Value of f_kws

<member 'f_kws' of 'Coroutine' objects>

lastop

Value of lastop

<member 'lastop' of 'Coroutine' objects>

name

Value of name

<member 'name' of 'Coroutine' objects>

prio

Value of prio

<member 'prio' of 'Coroutine' objects>

result

Value of result

<member 'result' of 'Coroutine' objects>

running

Value of running

<property object at 0x00E0DA08>

state

Value of state

<member 'state' of 'Coroutine' objects>

waiters

Value of waiters

<member 'waiters' of 'Coroutine' objects>