m4us.concurrency — Message For You Sir! v0.2.1 documentation

### Navigation

- index
- modules |
- next |
- previous |
- Message For You Sir! v0.2.1 documentation »
- API Documentation »

# `m4us.concurrency`

Provides support for concurrent execution of coroutines.

## Inheritance Diagram

## Members

class `ThreadedCoroutine`(coroutine, max_in_size=0, max_out_size=0, start=True)

  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 (`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 : | `IThreadedCoroutine` and `INotLazy`
  Provides : | `ICoroutineFactory`

  Example usage:

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

  See also

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

  `close`()

    Close the coroutine and shutdown it's thread.

    See also

    `ICoroutine` for details about this method.

  `send`(message)

    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`()

    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)

    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.

### Navigation

- index
- modules |
- next |
- previous |
- Message For You Sir! v0.2.1 documentation »
- API Documentation »