-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
38 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from curio import UniversalQueue, run, sleep, spawn | ||
from threading import Thread | ||
|
||
|
||
def consumer(queue): | ||
while True: | ||
item = queue.get() | ||
if item is None: | ||
break | ||
print('Got:', item) | ||
|
||
|
||
async def producer(n, m, queue): | ||
for x in range(n): | ||
await queue.put(x) | ||
await sleep(m) | ||
await queue.put(None) | ||
|
||
|
||
async def main(): | ||
q = UniversalQueue() | ||
Thread(target=consumer, args=(q,)).start() | ||
t = await spawn(producer, 100, 1, q) | ||
t1 = await spawn(producer, 100, 0.2, q) | ||
t2 = await spawn(producer, 100, 0.5, q) | ||
await t.join() | ||
await t1.join() | ||
await t2.join() | ||
run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters