Я просто портировал скрипт с помощью библиотеки multithreading
в библиотеку multiprocessing
, поэтому я сталкиваюсь с проблемами, связанными с тем, как память распределяется между процессами.Многопроцессорный цикл и условие остановки
Краткий обзор, мои работники потребляют очередь слов; когда работник находит удар, он должен boradcast сигнал (глобальная переменная или любая реализация), чтобы упорядочить остальные запущенные процессы для завершения.
Вот основной метод моих работников:
def run(self):
while not self.queue.empty():
entry = self.queue.get()
try:
payload = jwt.decode(self.token, entry, algorithm = 'HS256')
except jwt.InvalidTokenError:
if self.verbose:
print(DEBUG + "[{}] ".format(self.name) + "InvalidTokenError: " + Style.BRIGHT + entry + RESET)
continue
except jwt.DecodeError:
print(WARNING + "[{}] ".format(self.name) + "DecodingError: " + Style.BRIGHT + entry + RESET)
continue
except Exception as ex:
print(ERROR + "[{}] ".format(self.name) + "Exception: " + Style.BRIGHT + "{}".format(ex) + RESET)
continue
# Save the holy secret into a file in case sys.stdout is not responding
with open("jwtpot.pot", "a+") as file:
file.write("{0}:{1}:{2}".format(self.token, payload, entry))
print(RESULT + "[{}] ".format(self.name) + "Secret key saved to location: " + Style.BRIGHT + "{}".format(file.name) + RESET)
print(RESULT + "[{}] ".format(self.name) + "Secret key: " + Style.BRIGHT + entry + RESET)
print(RESULT + "[{}] ".format(self.name) + "Payload: " + Style.BRIGHT + "{}".format(payload) + RESET)
break
self.queue.task_done()
Вот как я создание экземпляра и начать свои процессы в моем основном:
# Load and segmentate the wordlist into the queue
print(INFO + "Processing the wordlist..." + RESET)
queue = populate_queue(queue, wordlist, verbose)
print(INFO + "Total retrieved words: " + Style.BRIGHT + "{}".format(queue.qsize()) + RESET)
for i in range(process_count):
process = Process(queue, token, verbose)
process.daemon = True
print(INFO + "Starting {}".format(process.name) + RESET)
process.start()
processes.append(process)
print(WARNING + "Pour yourself some coffee, this might take a while..." + RESET)
# Block the parent-process until all the child-processes finish to process the queue
for process in processes:
process.join()