-
Notifications
You must be signed in to change notification settings - Fork 0
/
threadingtest.py
62 lines (48 loc) · 1.15 KB
/
threadingtest.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'''
Created on Feb 12, 2013
@author: Riz
'''
from threading import Timer
import threading
import time
def kill_function():
print "being called by kill function"
list_of_thread = threading.enumerate()
print threading.enumerate()
for each_thread in list_of_thread:
print each_thread.name
if "MainThread" not in each_thread.name:
print "cancelling an orphan thread"
print each_thread
def another(x):
#print "i am another funciton"
#print x
while 1:
#print "now i am stuck in another function"
time.sleep(1)
if x ==1:
break
#print x
t = Timer(5, kill_function)
x = 1
y = 0
t.start()
print "number of active thread %s" %threading.activeCount()
while x==x:
print "looping"
time.sleep(1)
y =y +1
print "Thread status: %s" %t.is_alive()
print another(2)
if y == 6:
print "cancelling thread"
t.cancel()
break
#class MC(type):
# def __repr__(self):
# return 'Wahaha!'
#
#class C(object):
# __metaclass__ = MC
#
#print type(C)