forked from sqlmapproject/sqlmap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeout.py
More file actions
32 lines (25 loc) · 788 Bytes
/
timeout.py
File metadata and controls
32 lines (25 loc) · 788 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
#!/usr/bin/env python
"""
Copyright (c) 2006-2012 sqlmap developers (http://www.sqlmap.org/)
See the file 'doc/COPYING' for copying permission
"""
import threading
from lib.core.data import logger
def timeout(func, args=(), kwargs={}, duration=1, default=None):
class InterruptableThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.result = None
def run(self):
try:
self.result = func(*args, **kwargs)
except Exception, msg:
logger.log(7, msg)
self.result = default
thread = InterruptableThread()
thread.start()
thread.join(duration)
if thread.isAlive():
return default
else:
return thread.result