Provides support for concurrent execution of coroutines.
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: |
|
---|---|
Implements : | m4us.interfaces.IThreadedCoroutine and m4us.core.interfaces.INotLazy |
Provides : |
Example usage:
>>> scheduler.register(ThreadedCoroutine(my_coroutine()))
See also
The Python Queue.Queue class for more information on limiting queue sizes.
Close the coroutine and shutdown it's thread.
See also
ICoroutine for details about this method.
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 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 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.