We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e9d9ef6 commit b491d69Copy full SHA for b491d69
py3/advance/do_prod_cons.py
@@ -0,0 +1,27 @@
1
+#!/usr/bin/env python3
2
+# -*- coding: utf-8 -*-
3
+
4
+import time
5
6
+def consumer():
7
+ r = ''
8
+ while True:
9
+ n = yield r
10
+ if not n:
11
+ return
12
+ print('[CONSUMER] Consuming %s...' % n)
13
+ time.sleep(1)
14
+ r = '200 OK'
15
16
+def produce(c):
17
+ c.send(None)
18
+ n = 0
19
+ while n < 5:
20
+ n = n + 1
21
+ print('[PRODUCER] Producing %s...' % n)
22
+ r = c.send(n)
23
+ print('[PRODUCER] Consumer return: %s' % r)
24
+ c.close()
25
26
+c = consumer()
27
+produce(c)
0 commit comments