import thread sys def main print Main Thread thread get_ident count tr

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
import thread, sys
def main():
print "Main Thread:", thread.get_ident()
count = 0;
try:
while 1:
thread.start_new_thread(test,(count,))
count = count + 1;
except:
print "Total Threads:", count
print "Exiting Main Thread:", thread.get_ident()
raise
def test(input=None):
print "count:", thread.get_ident(), input
while 1: #keep thread alive until it breaks
pass
if __name__ == "__main__":
main()