Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9498a3f

Browse files
committed
little stabilization of multi threading
1 parent 2171c64 commit 9498a3f

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

lib/core/threads.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99

1010
import difflib
1111
import threading
12+
import time
1213

1314
from lib.core.data import kb
1415
from lib.core.data import logger
1516
from lib.core.datatype import advancedDict
1617
from lib.core.exception import sqlmapThreadException
1718
from lib.core.settings import MAX_NUMBER_OF_THREADS
19+
from lib.core.settings import PYVERSION
1820

1921
shared = advancedDict()
2022

@@ -98,20 +100,25 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
98100
# Start the threads
99101
for numThread in range(numThreads):
100102
thread = threading.Thread(target=exceptionHandledFunction, name=str(numThread), args=[threadFunction])
103+
104+
# Reference: http://stackoverflow.com/questions/190010/daemon-threads-explanation
105+
if PYVERSION >= "2.6":
106+
thread.daemon = True
107+
else:
108+
thread.setDaemon(True)
109+
101110
thread.start()
102111
threads.append(thread)
103112

104113
# And wait for them to all finish
105114
try:
106115
alive = True
107-
108116
while alive:
109117
alive = False
110-
111118
for thread in threads:
112119
if thread.isAlive():
113120
alive = True
114-
thread.join(1)
121+
time.sleep(1)
115122

116123
except KeyboardInterrupt:
117124
kb.threadContinue = False

lib/techniques/blind/inference.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
from lib.core.settings import INFERENCE_GREATER_CHAR
4444
from lib.core.settings import INFERENCE_EQUALS_CHAR
4545
from lib.core.settings import INFERENCE_NOT_EQUALS_CHAR
46+
from lib.core.settings import PYVERSION
4647
from lib.core.unescaper import unescaper
4748
from lib.request.connect import Connect as Request
4849

@@ -413,6 +414,12 @@ def downloadThread():
413414
# Start the threads
414415
for numThread in range(numThreads):
415416
thread = threading.Thread(target=downloadThread, name=str(numThread))
417+
418+
if PYVERSION >= "2.6":
419+
thread.daemon = True
420+
else:
421+
thread.setDaemon(True)
422+
416423
thread.start()
417424
threads.append(thread)
418425

@@ -424,7 +431,8 @@ def downloadThread():
424431
for thread in threads:
425432
if thread.isAlive():
426433
alive = True
427-
thread.join(5)
434+
time.sleep(1)
435+
428436
except KeyboardInterrupt:
429437
kb.threadContinue = False
430438
raise

sqlmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ def main():
129129
kb.threadContinue = False
130130
kb.threadException = True
131131

132-
# just in case handling of leftover threads
133-
raise SystemExit
132+
# Reference: http://stackoverflow.com/questions/1635080/terminate-a-multi-thread-python-program
133+
os._exit(0)
134134

135135
if __name__ == "__main__":
136136
main()

0 commit comments

Comments
 (0)