| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,12 +9,14 @@ | |||
| 9 | 9 | ||
| 10 | 10 | import difflib | |
| 11 | 11 | import threading | |
| 12 | + import time | ||
| 12 | 13 | ||
| 13 | 14 | from lib.core.data import kb | |
| 14 | 15 | from lib.core.data import logger | |
| 15 | 16 | from lib.core.datatype import advancedDict | |
| 16 | 17 | from lib.core.exception import sqlmapThreadException | |
| 17 | 18 | from lib.core.settings import MAX_NUMBER_OF_THREADS | |
| 19 | + from lib.core.settings import PYVERSION | ||
| 18 | 20 | ||
| 19 | 21 | shared = advancedDict() | |
| 20 | 22 | ||
@@ -98,20 +100,25 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio | |||
| 98 | 100 | # Start the threads | |
| 99 | 101 | for numThread in range(numThreads): | |
| 100 | 102 | 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 | + | ||
| 101 | 110 | thread.start() | |
| 102 | 111 | threads.append(thread) | |
| 103 | 112 | ||
| 104 | 113 | # And wait for them to all finish | |
| 105 | 114 | try: | |
| 106 | 115 | alive = True | |
| 107 | - | ||
| 108 | 116 | while alive: | |
| 109 | 117 | alive = False | |
| 110 | - | ||
| 111 | 118 | for thread in threads: | |
| 112 | 119 | if thread.isAlive(): | |
| 113 | 120 | alive = True | |
| 114 | - thread.join(1) | ||
| 121 | + time.sleep(1) | ||
| 115 | 122 | ||
| 116 | 123 | except KeyboardInterrupt: | |
| 117 | 124 | kb.threadContinue = False | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,7 @@ | |||
| 43 | 43 | from lib.core.settings import INFERENCE_GREATER_CHAR | |
| 44 | 44 | from lib.core.settings import INFERENCE_EQUALS_CHAR | |
| 45 | 45 | from lib.core.settings import INFERENCE_NOT_EQUALS_CHAR | |
| 46 | + from lib.core.settings import PYVERSION | ||
| 46 | 47 | from lib.core.unescaper import unescaper | |
| 47 | 48 | from lib.request.connect import Connect as Request | |
| 48 | 49 | ||
@@ -413,6 +414,12 @@ def downloadThread(): | |||
| 413 | 414 | # Start the threads | |
| 414 | 415 | for numThread in range(numThreads): | |
| 415 | 416 | 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 | + | ||
| 416 | 423 | thread.start() | |
| 417 | 424 | threads.append(thread) | |
| 418 | 425 | ||
@@ -424,7 +431,8 @@ def downloadThread(): | |||
| 424 | 431 | for thread in threads: | |
| 425 | 432 | if thread.isAlive(): | |
| 426 | 433 | alive = True | |
| 427 | - thread.join(5) | ||
| 434 | + time.sleep(1) | ||
| 435 | + | ||
| 428 | 436 | except KeyboardInterrupt: | |
| 429 | 437 | kb.threadContinue = False | |
| 430 | 438 | raise | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -129,8 +129,8 @@ def main(): | |||
| 129 | 129 | kb.threadContinue = False | |
| 130 | 130 | kb.threadException = True | |
| 131 | 131 | ||
| 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) | ||
| 134 | 134 | ||
| 135 | 135 | if __name__ == "__main__": | |
| 136 | 136 | main() | |
| Back | FazBrowse Home | New Git URL |
0 commit comments