2010-04-06 18:33:57 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2010-04-07 00:40:14 +04:00
|
|
|
"""
|
|
|
|
$Id$
|
|
|
|
|
2011-07-08 00:10:03 +04:00
|
|
|
Copyright (c) 2006-2011 sqlmap developers (http://www.sqlmap.org/)
|
2010-10-15 03:18:29 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
2010-04-07 00:40:14 +04:00
|
|
|
"""
|
|
|
|
|
2010-04-06 18:33:57 +04:00
|
|
|
import threading
|
|
|
|
|
2010-04-06 19:24:56 +04:00
|
|
|
from lib.core.data import logger
|
|
|
|
|
2010-04-06 18:59:31 +04:00
|
|
|
def timeout(func, args=(), kwargs={}, duration=1, default=None):
|
2010-04-06 18:33:57 +04: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 19:24:56 +04:00
|
|
|
except Exception, msg:
|
2010-11-08 01:34:29 +03:00
|
|
|
logger.log(7, msg)
|
2010-04-06 18:33:57 +04:00
|
|
|
self.result = default
|
|
|
|
|
|
|
|
thread = InterruptableThread()
|
|
|
|
thread.start()
|
2010-04-06 18:59:31 +04:00
|
|
|
thread.join(duration)
|
2010-04-07 00:40:14 +04:00
|
|
|
|
2010-04-06 19:28:34 +04:00
|
|
|
if thread.isAlive():
|
2010-04-06 18:33:57 +04:00
|
|
|
return default
|
|
|
|
else:
|
|
|
|
return thread.result
|