-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcore_test.py
67 lines (52 loc) · 1.76 KB
/
core_test.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
# -*- coding: utf-8 -*-
from multiprocessing import Process, Queue, current_process
from time import sleep
functionQueue = Queue()
Queue_2 = Queue()
Queue_3 = Queue()
def fast_loop():
while True:
pass
def test_process_1():
""" Function to run a loop that processes functions in queue. """
print current_process().name, 'starting'
while True:
items = functionQueue.get()
func = items[0]
args = items[1:]
if func:
func(*args)
def test_process_2():
""" Function to run a loop that processes functions in queue. """
print current_process().name, 'starting'
while True:
items = Queue_2.get()
func = items[0]
args = items[1:]
if func:
func(*args)
def test_process_3():
""" Function to run a loop that processes functions in queue."""
print current_process().name, 'starting'
while True:
items = Queue_3.get()
func = items[0]
args = items[1:]
if func:
func(*args)
def main():
print current_process().name, 'starting'
# functionQueue.put((fast_loop,))
# Queue_2.put((fast_loop,))
# Queue_3.put((fast_loop,))
while True:
print "main is running"
sleep(5)
if __name__ == '__main__':
# comment out main() and uncomment the following line to enable multiprocess operation
main()
# p1 = Process(name = "Main", target=main,).start()
p2 = Process(name = "Test Process 1", target=test_process_1,).start()
p3 = Process(name = "Test Process 2", target=test_process_2,).start()
p4 = Process(name = "Test Process 3", target=test_process_3,).start()