@@ -536,9 +536,9 @@ except IndexError:
536
536
537
537
# 8. Threadsafe Queue
538
538
539
- This queue is designed to interface between one or more ` uasyncio ` tasks and a
540
- single thread running in a different context. This can be an interrupt service
541
- routine (ISR) or code running in a different thread or on a different core.
539
+ This queue is designed to interface between one ` uasyncio ` task and a single
540
+ thread running in a different context. This can be an interrupt service routine
541
+ (ISR), code running in a different thread or code on a different core.
542
542
543
543
Any Python object may be placed on a ` ThreadSafeQueue ` . If bi-directional
544
544
communication is required between the two contexts, two ` ThreadSafeQueue `
@@ -556,7 +556,7 @@ Constructor mandatory arg:
556
556
* ` buf ` Buffer for the queue, e.g. list ` [0 for _ in range(20)] ` or array. A
557
557
buffer of size ` N ` can hold a maximum of ` N-1 ` items.
558
558
559
- Synchronous methods (immediate return):
559
+ Synchronous methods.
560
560
* ` qsize ` No arg. Returns the number of items in the queue.
561
561
* ` empty ` No arg. Returns ` True ` if the queue is empty.
562
562
* ` full ` No arg. Returns ` True ` if the queue is full.
@@ -567,6 +567,9 @@ Synchronous methods (immediate return):
567
567
` IndexError ` if the queue is full unless ` block==True ` in which case the
568
568
method blocks until the ` uasyncio ` tasks remove an item from the queue.
569
569
570
+ The blocking methods should not be used in the ` uasyncio ` context, because by
571
+ blocking they will lock up the scheduler.
572
+
570
573
Asynchronous methods:
571
574
* ` put ` Arg: the object to put on the queue. If the queue is full, it will
572
575
block until space is available.
@@ -579,12 +582,8 @@ Data consumer:
579
582
``` python
580
583
async def handle_queued_data (q ):
581
584
async for obj in q:
582
- await asyncio.sleep(0 ) # See below
583
585
# Process obj
584
586
```
585
- The ` sleep ` is necessary if you have multiple tasks waiting on the queue,
586
- otherwise one task hogs all the data.
587
-
588
587
Data provider:
589
588
``` python
590
589
async def feed_queue (q ):
0 commit comments