Debian Codegraph @

rpython/translator/goal/_test_thread.py

raw symbols SCIP
1 import thread
2
3 class MonitorList(list):
4 def append(self, obj):
5 list.append(self, obj)
6 print "running grown to %r\n" % self,
7 def remove(self, obj):
8 list.remove(self, obj)
9 print "running shrunk to %r\n" % self,
10
11 running = MonitorList()
12
13 def f(name, count, modulus):
14 running.append(name)
15 print "starting %s %d %d\n" % (name, count, modulus),
16 for i in xrange(count):
17 if i % modulus == 0:
18 print "%s %d\n" % (name, i),
19 running.remove(name)
20
21 thread.start_new_thread(f, ("eins", 10000000, 12345))
22 thread.start_new_thread(f, ("zwei", 10000000, 13579))
23 thread.start_new_thread(f, ("drei", 10000000, 14680))
24 thread.start_new_thread(f, ("vier", 10000000, 15725))
25
26 while not running:
27 pass
28 print "waiting for %r to finish\n" % running,
29 while running:
30 pass
31 print "finished waiting.\n",
32