m4us.concurrency

Provides support for concurrent execution of coroutines.

Inheritance Diagram

Inheritance diagram of m4us.concurrency

Members

class ThreadedCoroutine(coroutine, max_in_size=0, max_out_size=0, start=True)[source]

Bases: object

Wrapper that runs a coroutine in a separate thread.

This class is an analog to Kamaelia's ThreadedComponent class but is meant to be used on any coroutine or component.

This class uses thread-safe queues for message and exception delivery. Method calls on this class will always return immediately, merely queueing up messages to be delivered to and from the given coroutine. The exception is when either of the queue sizes are set and the queue is full. In that case, a method will hang until room becomes available in the queue.

Parameters:
  • coroutine (m4us.core.interfaces.ICoroutine) -- The coroutine to run in it's own thread.
  • max_in_size (int) -- The maximum input queue size. 0 means unlimited.
  • max_out_size (int) -- The maximum output queue size. 0 means unlimited.
  • start (bool) -- Whether or not to automatically start the thread. If disabled, the start() method must be called explicitly.
Implements :

m4us.interfaces.IThreadedCoroutine and m4us.core.interfaces.INotLazy

Provides :

m4us.core.interfaces.ICoroutineFactory

Example usage:

>>> scheduler.register(ThreadedCoroutine(my_coroutine()))

See also

The Python Queue.Queue class for more information on limiting queue sizes.

close()[source]

Close the coroutine and shutdown it's thread.

See also

ICoroutine for details about this method.

send(message)[source]

Send and receive messages to and from the coroutine.

Note

('control', None) inbox messages will only be sent to the coroutine if it is not lazy (i.e. it provides the INotLazy marker interface).

Note

Any message returned will be the next one in the output queue, and not necessarily the immediate response to the given message when sent.

See also

ICoroutine for details about this method.

start()[source]

Start the coroutine thread if it needs explicit starting.

See also

IThreadedCoroutine for details about this method.

See also

This class's docstring for details about the implicit and explicit starting of the coroutine thread.

throw(exception)[source]

Throw an exception inside the threaded coroutine.

Note

The thrown exception is queued up, in order, with other sent messages and so the threaded coroutine may not react to it immediately.

Note

Like the send() method, any message returned will be the next one in the output queue, and not necessarily the immediate response given exception. This includes the raising of any handled exceptions.

See also

ICoroutine for details about this method.

Table Of Contents

Previous topic

m4us.backplanes

Next topic

m4us.interfaces

This Page