sqlmap/lib/utils/timeout.py
Miroslav Stampar 3fe9f9cac9 another fix
2010-04-06 15:28:34 +00:00

27 lines
661 B
Python

#!/usr/bin/env python
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(8, msg)
self.result = default
thread = InterruptableThread()
thread.start()
thread.join(duration)
if thread.isAlive():
return default
else:
return thread.result