mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2024-11-25 11:03:47 +03:00
little stabilization of multi threading
This commit is contained in:
parent
2171c64213
commit
9498a3f259
|
@ -9,12 +9,14 @@ See the file 'doc/COPYING' for copying permission
|
||||||
|
|
||||||
import difflib
|
import difflib
|
||||||
import threading
|
import threading
|
||||||
|
import time
|
||||||
|
|
||||||
from lib.core.data import kb
|
from lib.core.data import kb
|
||||||
from lib.core.data import logger
|
from lib.core.data import logger
|
||||||
from lib.core.datatype import advancedDict
|
from lib.core.datatype import advancedDict
|
||||||
from lib.core.exception import sqlmapThreadException
|
from lib.core.exception import sqlmapThreadException
|
||||||
from lib.core.settings import MAX_NUMBER_OF_THREADS
|
from lib.core.settings import MAX_NUMBER_OF_THREADS
|
||||||
|
from lib.core.settings import PYVERSION
|
||||||
|
|
||||||
shared = advancedDict()
|
shared = advancedDict()
|
||||||
|
|
||||||
|
@ -98,20 +100,25 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
|
||||||
# Start the threads
|
# Start the threads
|
||||||
for numThread in range(numThreads):
|
for numThread in range(numThreads):
|
||||||
thread = threading.Thread(target=exceptionHandledFunction, name=str(numThread), args=[threadFunction])
|
thread = threading.Thread(target=exceptionHandledFunction, name=str(numThread), args=[threadFunction])
|
||||||
|
|
||||||
|
# Reference: http://stackoverflow.com/questions/190010/daemon-threads-explanation
|
||||||
|
if PYVERSION >= "2.6":
|
||||||
|
thread.daemon = True
|
||||||
|
else:
|
||||||
|
thread.setDaemon(True)
|
||||||
|
|
||||||
thread.start()
|
thread.start()
|
||||||
threads.append(thread)
|
threads.append(thread)
|
||||||
|
|
||||||
# And wait for them to all finish
|
# And wait for them to all finish
|
||||||
try:
|
try:
|
||||||
alive = True
|
alive = True
|
||||||
|
|
||||||
while alive:
|
while alive:
|
||||||
alive = False
|
alive = False
|
||||||
|
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
if thread.isAlive():
|
if thread.isAlive():
|
||||||
alive = True
|
alive = True
|
||||||
thread.join(1)
|
time.sleep(1)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
kb.threadContinue = False
|
kb.threadContinue = False
|
||||||
|
|
|
@ -43,6 +43,7 @@ from lib.core.settings import INFERENCE_UNKNOWN_CHAR
|
||||||
from lib.core.settings import INFERENCE_GREATER_CHAR
|
from lib.core.settings import INFERENCE_GREATER_CHAR
|
||||||
from lib.core.settings import INFERENCE_EQUALS_CHAR
|
from lib.core.settings import INFERENCE_EQUALS_CHAR
|
||||||
from lib.core.settings import INFERENCE_NOT_EQUALS_CHAR
|
from lib.core.settings import INFERENCE_NOT_EQUALS_CHAR
|
||||||
|
from lib.core.settings import PYVERSION
|
||||||
from lib.core.unescaper import unescaper
|
from lib.core.unescaper import unescaper
|
||||||
from lib.request.connect import Connect as Request
|
from lib.request.connect import Connect as Request
|
||||||
|
|
||||||
|
@ -413,6 +414,12 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
|
||||||
# Start the threads
|
# Start the threads
|
||||||
for numThread in range(numThreads):
|
for numThread in range(numThreads):
|
||||||
thread = threading.Thread(target=downloadThread, name=str(numThread))
|
thread = threading.Thread(target=downloadThread, name=str(numThread))
|
||||||
|
|
||||||
|
if PYVERSION >= "2.6":
|
||||||
|
thread.daemon = True
|
||||||
|
else:
|
||||||
|
thread.setDaemon(True)
|
||||||
|
|
||||||
thread.start()
|
thread.start()
|
||||||
threads.append(thread)
|
threads.append(thread)
|
||||||
|
|
||||||
|
@ -424,7 +431,8 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
if thread.isAlive():
|
if thread.isAlive():
|
||||||
alive = True
|
alive = True
|
||||||
thread.join(5)
|
time.sleep(1)
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
kb.threadContinue = False
|
kb.threadContinue = False
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -129,8 +129,8 @@ def main():
|
||||||
kb.threadContinue = False
|
kb.threadContinue = False
|
||||||
kb.threadException = True
|
kb.threadException = True
|
||||||
|
|
||||||
# just in case handling of leftover threads
|
# Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program
|
||||||
raise SystemExit
|
os._exit(0)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user