Asynchronous API

pydle.coroutine(func)[source]

Decorator to mark coroutines.

If the coroutine is not yielded from before it is destroyed, an error message is logged.

class pydle.Future

This class is almost compatible with concurrent.futures.Future.

Differences:

  • result() and exception() do not take a timeout argument and raise an exception when the future isn’t done yet.
  • Callbacks registered with add_done_callback() are always called via the event loop’s call_soon_threadsafe().
  • This class is not compatible with the wait() and as_completed() methods in the concurrent.futures package.
done()

Return True if the future is done.

Done means either that a result / exception are available, or that the future was cancelled.

result()

Return the result this future represents.

If the future has been cancelled, raises CancelledError. If the future’s result isn’t yet available, raises InvalidStateError. If the future is done and has an exception set, this exception is raised.

set_result()

Mark the future done and set its result.

If the future is already done when this method is called, raises InvalidStateError.

exception()

Return the exception that was set on this future.

The exception (or None if no exception was set) is returned only if the future is done. If the future has been cancelled, raises CancelledError. If the future isn’t done yet, raises InvalidStateError.

set_exception()

Mark the future done and set an exception.

If the future is already done when this method is called, raises InvalidStateError.