forked from akkana/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmpcdemo.py
More file actions
executable file
·36 lines (28 loc) · 744 Bytes
/
mpcdemo.py
File metadata and controls
executable file
·36 lines (28 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
# An example of how to do work in a separate thread and send messages to it.
import multiprocessing
import time
import sys
def worker(q):
print "Starting worker"
while True:
print ".",
sys.stdout.flush()
time.sleep(2)
if not q.empty():
num = q.get(block=False)
print "Got a message:", num
if num < 0:
return
if __name__ == '__main__':
queue = multiprocessing.Queue()
p = multiprocessing.Process(target=worker, args=(queue,))
p.start()
for i in range(5):
time.sleep(5)
queue.put(i)
queue.put(-1)
# Wait for the worker to finish
queue.close()
queue.join_thread()
p.join()