usr bin env python from multiprocessing import Process import time PRO

 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
#!/usr/bin/env python
from multiprocessing import Process
import time
PROCESSES_NUM = 5
def get_element(x):
if not x:
return None
return x.pop(0)
def f(x):
element = get_element(x)
while element:
for _ in xrange(0, 1):
print element
time.sleep(1)
element = get_element(list)
words_list = ['a', 'b', 'c', 'd', 'e', 'f', 'j', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r']
processes_list = []
if __name__ == '__main__':
for i in xrange(0, PROCESSES_NUM - 1):
processes_list.append(Process(target=f, args=(words_list,)))
processes_list[i].start()
for p in processes_list:
p.join()
print 'ALL PROCESSES DONE'