mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2024-11-22 17:46:37 +03:00
34 lines
850 B
Python
34 lines
850 B
Python
#!/usr/bin/env python
|
|
|
|
"""
|
|
Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/)
|
|
See the file 'doc/COPYING' for copying permission
|
|
"""
|
|
|
|
import threading
|
|
|
|
from lib.core.data import logger
|
|
from lib.core.enums import CUSTOM_LOGGING
|
|
|
|
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(CUSTOM_LOGGING.TRAFFIC_IN, msg)
|
|
self.result = default
|
|
|
|
thread = InterruptableThread()
|
|
thread.start()
|
|
thread.join(duration)
|
|
|
|
if thread.isAlive():
|
|
return default
|
|
else:
|
|
return thread.result
|