Jun-08-2017, 01:02 PM
Does this help?
class PasswordFoundException (Exception): pass def attempt(w, pw): # sys.stdout.write("\r") # sys.stdout.write("\rAttempt #%d: %s" % (counter.value, pw)) #prints simple progress with # in list that is tested and the pw string sys.stdout.write("Attempt #%d: %s\n" % (counter.value, pw)) #prints simple progress with # in list that is tested and the pw string sys.stdout.flush() #print(counter.value) counter.increment() if len(pw) < 10: return "" try: o = decode_keystore_json(w,pw) print("Password is: ", pw, " ", o) raise PasswordFoundException("Password Found") except ValueError as e: # print(e) return "" class Counter(object): def __init__(self): self.val = multiprocessing.Value('i', 0) def increment(self, n=1): with self.val.get_lock(): self.val.value += n @property def value(self): return self.val.value def __main__(): global counter counter = Counter() pwds = [] pwds = itertools.chain(pwds, generate_all(grammar,'')) try: Parallel(n_jobs=-1)(delayed(attempt)(w, pw) for pw in pwds) except Exception as e: traceback.print_exc() while True: sys.stdout.write('\a') sys.stdout.flush() if __name__ == "__main__": __main__()