mode.utils.queues¶
Queue utilities - variations of asyncio.Queue.
-
class
mode.utils.queues.FlowControlEvent(*, initially_suspended: bool = True, loop: asyncio.events.AbstractEventLoop = None)[source]¶ Manage flow control
FlowControlQueueinstances.The FlowControlEvent manages flow in one or many queue instances at the same time.
To flow control queues, first create the shared event:
>>> flow_control = FlowControlEvent()
Then pass that shared event to the queues that should be managed by it:
>>> q1 = FlowControlQueue(maxsize=1, flow_control=flow_control) >>> q2 = FlowControlQueue(flow_control=flow_control)
If you want the contents of the queue to be cleared when flow is resumed, then specify that by using the
clear_on_resumeflag:>>> q3 = FlowControlQueue(clear_on_resume=True, ... flow_control=flow_control)
To suspend production into queues, use
flow_control.suspend:>>> flow_control.suspend()
While the queues are suspend, any producer attempting to send something to the queue will hang until flow is resumed.
To resume production into queues, use
flow_control.resume:>>> flow_control.resume()
Notes
In Faust queues are managed by the
app.flow_controlevent.-
manage_queue(queue: mode.utils.queues.FlowControlQueue) → None[source]¶ Add
FlowControlQueueto be cleared on resume.
-
-
class
mode.utils.queues.FlowControlQueue(maxsize: int = 0, *, flow_control: mode.utils.queues.FlowControlEvent = None, clear_on_resume: bool = False, **kwargs: Any)[source]¶ asyncio.Queuemanaged byFlowControlEvent.See also