usr bin env python from threading import Thread import time PROCESSES_

 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
#!/usr/bin/env python
from threading import Thread
import time
PROCESSES_NUM = 4
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, 2):
words_result.append(element)
element = get_element(x)
words_list = ['a', 'b', 'c', 'd', 'e', 'f', 'j', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r']
words_result = []
processes_list = []
if __name__ == '__main__':
for i in xrange(0, PROCESSES_NUM - 1):
processes_list.append(Thread(target=f, args=(words_list,)))
processes_list[i].start()
for p in processes_list:
p.join()
print words_result
print 'ALL PROCESSES DONE'