Package coro :: Module _coro :: Class sched
[hide private]
[frames] | no frames]

Class sched

object --+
         |
        sched

Instance Methods [hide private]
 
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature
a new object with type S, a subtype of T
__new__(T, S, ...)
 
current(...)
 
event_loop(...)
Start the event loop.
 
set_latency_warning(...)
Set the latency warning threshold multiplier.
 
sleep_absolute(...)
This is an alias for the sleep method.
 
sleep_relative(...)
Sleep for a period of time.
 
with_timeout(...)
Call a function with a timeout.

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]
  _current
  events
  pending
  staging

Inherited from object: __class__

Method Details [hide private]

__init__(...)
(Constructor)

 
x.__init__(...) initializes x; see help(type(x)) for signature
Overrides: object.__init__

__new__(T, S, ...)

 
Returns: a new object with type S, a subtype of T
Overrides: object.__new__

event_loop(...)

 
Start the event loop.
Parameters:
  • timeout - : The amount of time to wait for kevent to return events. You should probably not set this value. Defaults to 30 seconds.

set_latency_warning(...)

 

Set the latency warning threshold multiplier.

The default latency warning threshold is 0.2 seconds. This will allow you to change the threshold by multiplying the 0.2 value.

Parameters:
  • factor - : The latency threshold multiplier. May be a number from 0 to 300. A value of 0 disables latency warnings.
Returns:
Returns the old multipler factor.
Raises:
  • ValueError - : The factor is too small or too large.

sleep_relative(...)

 

Sleep for a period of time.

If a thread is interrupted at the exact same time the sleep is finished, it is not defined whether the interrupt or the sleep "wins". Your thread may continue running (with the interrupt rescheduled to try again later), or it may be interrupted.

Parameters:
  • delta - : The number of seconds to sleep.

with_timeout(...)

 

Call a function with a timeout.

Additional arguments and keyword arguments provided are passed to the function. This will re-raise any exceptions raised by the function.

If a timeout expires, but the function returns before the next pass in the event loop, then the timeout will be diffused.

If a coroutine is already scheduled to run (such as if it received a kevent), and the timeout expires, the timeout will be put on "hold" to let the coroutine run and process the data. If the function returns, then the timeout will be defused, otherwise the timeout will be given another chance to fire during the next pass through the event loop. One should note that due to this behavior, if a coroutine is continually receiving kevents, the timeout will never fire until the kevents stop.

Nested timeouts will be handled correctly. If an outer timeout fires first, then only the outer except TimeoutError exception handler will catch it. An exception handlers on the inside will be skipped becaue the actual exception is the Interrupted exception until it gets to the original with_timeout frame.

Nested timeouts that are set to fire at the exact same time are not defined which one will fire first.

Care must be taken to never catch the Interrupted exception within code that is wrapped with a timeout.

Returns:
Returns the return value of the function.
Raises:
  • TimeoutError - : The function did not return within the specified timeout.

Parameters:

  • delta: The number of seconds to wait before raising a timeout.

    Should be >= 0. Negative value will be treated as 0.

  • function: The function to call.