mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-02-03 05:04:11 +03:00
new module for interruptable threads
This commit is contained in:
parent
bd669dd6fa
commit
60f04f0a41
23
lib/utils/timeout.py
Normal file
23
lib/utils/timeout.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import threading
|
||||
|
||||
def timeout(func, args=(), kwargs={}, timeout_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:
|
||||
self.result = default
|
||||
|
||||
thread = InterruptableThread()
|
||||
thread.start()
|
||||
thread.join(timeout_duration)
|
||||
if thread.isAlive():
|
||||
return default
|
||||
else:
|
||||
return thread.result
|
Loading…
Reference in New Issue
Block a user