- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeout_test.py
More file actions
Latest commit
32 lines (28 loc) · 739 Bytes
/
Copy pathtimeout_test.py
File metadata and controls
32 lines (28 loc) · 739 Bytes
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
# coding:utf-8
importtime
fromthreadingimportTimer
classTimeOutError(Exception):
def__init__(self, value):
self.value=value
def__str__(self):
returnrepr(self.value)
deftimeout(interval):
defwraps(func):
deftime_out():
raiseTimeOutError('TimeOut: '+str(interval))
defdeco(*args, **kwargs):
timer=Timer(interval, time_out)
timer.start()
res=func(*args, **kwargs)
timer.cancel()
returnres
returndeco
returnwraps
@timeout(5)
defmytest():
print("Start")
foriinrange(1,10):
time.sleep(1)
print("%d seconds have passed"%i)
if__name__=='__main__':
mytest()