-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmp.test
More file actions
41 lines (36 loc) · 1.2 KB
/
mp.test
File metadata and controls
41 lines (36 loc) · 1.2 KB
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
37
38
39
40
41
import numpy as np
import multiprocessing as mp
import time
import sys
import logging
logger = logging.getLogger('app')
logger.setLevel(logging.INFO)
fh = logging.FileHandler('app.log')
fh.setLevel(logging.INFO)
logger.addHandler(fh)
def target(q, delay_secs=1.0):
while True:
if q.qsize() > 0:
logger.info("data detected")
data = q.get()
logger.info("printing data: \"{}\"".format(data))
print(data)
time.sleep(delay_secs)
logger.info("sucessfully printed to console")
logger.info("queue now contains {} data".format(q.qsize()))
if __name__ == '__main__':
q = mp.Queue(100)
args = q
kwargs = {'delay_secs': 1.0,}
p = mp.Process(target=target, args=(args,), kwargs=kwargs).start()
while True:
try:
data = input()
logger.info("putting data: \"{}\" into queue".format(data))
q.put(data)
logger.info("queue now contains {} data".format(q.qsize()))
except KeyboardInterrupt:
logger.info("Keyboard Interrupt detected. Joining process...")
p.join()
logger.info("Success. Exiting program")
sys.exit()