2010-04-06 14:33:57 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
2010-04-06 20:40:14 +00:00
|
|
|
"""
|
2012-07-12 18:38:03 +01:00
|
|
|
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
|
2010-10-14 23:18:29 +00:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
2010-04-06 20:40:14 +00:00
|
|
|
"""
|
|
|
|
|
|
2010-04-06 14:33:57 +00:00
|
|
|
import threading
|
|
|
|
|
|
2010-04-06 15:24:56 +00:00
|
|
|
from lib.core.data import logger
|
|
|
|
|
|
2010-04-06 14:59:31 +00:00
|
|
|
def timeout(func, args=(), kwargs={}, duration=1, default=None):
|
2010-04-06 14:33:57 +00:00
|
|
|
class InterruptableThread(threading.Thread):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
|
self.result = None
|
|
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
try:
|
|
|
|
|
self.result = func(*args, **kwargs)
|
2010-04-06 15:24:56 +00:00
|
|
|
except Exception, msg:
|
2010-11-07 22:34:29 +00:00
|
|
|
logger.log(7, msg)
|
2010-04-06 14:33:57 +00:00
|
|
|
self.result = default
|
|
|
|
|
|
|
|
|
|
thread = InterruptableThread()
|
|
|
|
|
thread.start()
|
2010-04-06 14:59:31 +00:00
|
|
|
thread.join(duration)
|
2010-04-06 20:40:14 +00:00
|
|
|
|
2010-04-06 15:28:34 +00:00
|
|
|
if thread.isAlive():
|
2010-04-06 14:33:57 +00:00
|
|
|
return default
|
|
|
|
|
else:
|
|
|
|
|
return thread.result
|