Skip to content
Snippets Groups Projects
Commit c1a87bd6 authored by Thibault Debatty's avatar Thibault Debatty
Browse files

add global RUN flag to stop the threads if needed

parent 264c5a97
No related branches found
No related tags found
No related merge requests found
Pipeline #10423 failed
......@@ -16,6 +16,7 @@ import validators
# https://superfastpython.com/thread-safe-print-in-python/
LOCK = Lock()
RUN = True
ARGS = None
FOUND = []
......@@ -80,6 +81,9 @@ def try_passwords(passwords):
'''
for password in passwords :
# we were interrupted by user
if not RUN :
break
password = password.strip()
print_safe("login: " + ARGS.login + " password: " + password)
try_password(password)
......@@ -179,7 +183,7 @@ def main():
# https://stackoverflow.com/a/15143994
executor = concurrent.futures.ThreadPoolExecutor(ARGS.threads)
futures = [executor.submit(try_passwords, group)
for group in batched(passwords, 10)]
for group in batched(passwords, ppt)]
# https://stackoverflow.com/a/65207578
try:
......@@ -187,6 +191,8 @@ def main():
except KeyboardInterrupt:
# User interrupt the program with ctrl+c
print_safe("Stopping threads...")
global RUN
RUN = False
executor.shutdown(wait=True, cancel_futures=True)
sys.exit()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment