(numThreads, threadFunction, cleanupFunction=None, forwardException=True, threadChoice=False, startThreadMsg=True)
| 120 | thread.setDaemon(True) |
| 121 | |
| 122 | def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardException=True, threadChoice=False, startThreadMsg=True): |
| 123 | threads = [] |
| 124 | |
| 125 | def _threadFunction(): |
| 126 | try: |
| 127 | threadFunction() |
| 128 | finally: |
| 129 | if conf.hashDB: |
| 130 | conf.hashDB.close() |
| 131 | |
| 132 | kb.multipleCtrlC = False |
| 133 | kb.threadContinue = True |
| 134 | kb.threadException = False |
| 135 | kb.technique = ThreadData.technique |
| 136 | kb.multiThreadMode = False |
| 137 | |
| 138 | try: |
| 139 | if threadChoice and conf.threads == numThreads == 1 and not (kb.injection.data and not any(_ not in (PAYLOAD.TECHNIQUE.TIME, PAYLOAD.TECHNIQUE.STACKED) for _ in kb.injection.data)): |
| 140 | while True: |
| 141 | message = "please enter number of threads? [Enter for %d (current)] " % numThreads |
| 142 | choice = readInput(message, default=str(numThreads)) |
| 143 | if choice: |
| 144 | skipThreadCheck = False |
| 145 | |
| 146 | if choice.endswith('!'): |
| 147 | choice = choice[:-1] |
| 148 | skipThreadCheck = True |
| 149 | |
| 150 | if isDigit(choice): |
| 151 | if int(choice) > MAX_NUMBER_OF_THREADS and not skipThreadCheck: |
| 152 | errMsg = "maximum number of used threads is %d avoiding potential connection issues" % MAX_NUMBER_OF_THREADS |
| 153 | logger.critical(errMsg) |
| 154 | else: |
| 155 | conf.threads = numThreads = int(choice) |
| 156 | break |
| 157 | |
| 158 | if numThreads == 1: |
| 159 | warnMsg = "running in a single-thread mode. This could take a while" |
| 160 | logger.warning(warnMsg) |
| 161 | |
| 162 | if numThreads > 1: |
| 163 | if startThreadMsg: |
| 164 | infoMsg = "starting %d threads" % numThreads |
| 165 | logger.info(infoMsg) |
| 166 | else: |
| 167 | try: |
| 168 | _threadFunction() |
| 169 | except (SqlmapUserQuitException, SqlmapSkipTargetException): |
| 170 | pass |
| 171 | return |
| 172 | |
| 173 | kb.multiThreadMode = True |
| 174 | |
| 175 | # Start the threads |
| 176 | for numThread in xrange(numThreads): |
| 177 | thread = threading.Thread(target=exceptionHandledFunction, name=str(numThread), args=[_threadFunction]) |
| 178 | |
| 179 | setDaemon(thread) |
no test coverage detected
searching dependent graphs…