Skip to content

Latest commit

 

History

History
95 lines (69 loc) · 3.33 KB

threads.rst

File metadata and controls

95 lines (69 loc) · 3.33 KB

Multi-threaded Use Notes

To ensure that the network communication module at the core of rabbitpy is thread safe, the :pyrabbitpy.io.IO class is a daemonic Python thread that uses a combination of :pythreading.Event, :pyQueue.Queue, and a local cross-platform implementation of a read-write socket pair in :pyrabbitpy.IO.write_trigger.

While ensuring that the core socket IO and dispatching of AMQP frames across threads goes a long way to make sure that multi-threaded applications can safely use rabbitpy, it does not protect against cross-thread channel utilization.

Due to the way that channels events are managed, it is recommend that you restrict the use of a channel to an individual thread. By not sharing channels across threads, you will ensure that you do not accidentally create issues with channel state in the AMQP protocol. As an asynchronous RPC style protocol, when you issue commands, such as a queue declaration, or are publishing a message, there are expectations in the conversation on a channel about the order of events and frames sent and received.

The following example uses the main Python thread to connect to RabbitMQ and then spawns a thread for publishing and a thread for consuming.