from threading import Thread import time def do_stuff id fp for in ran

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
from threading import Thread
import time
def do_stuff(id, fp):
for i in range(5):
fp.write("flow %d, packet %d\n" % (id, i))
time.sleep(0.1)
fp = open('/tmp/huis', 'w')
doers = []
for i in range(5):
t = Thread(target=do_stuff, args=(i,fp))
doers.append(t)
t.start()
for t in doers:
t.join()
fp.close()
print open('/tmp/huis').read()