Advertisement
Guest User

Untitled

a guest
May 14th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. from time import time, sleep
  2. from threading import Thread
  3. import Queue
  4.  
  5. lines = "pichlist.txt"
  6. number_of_thread = input("Enter the number of thread that you want to use:  ")
  7. user_name = "Doriane"
  8. user_password = "12121212"
  9.  
  10.  
  11. def autenti(user, passwd):
  12.         sleep(0.2)
  13.         correct = (user == user_name and passwd == user_password)
  14.         print correct
  15.         return correct
  16.  
  17.  
  18. def thread_job(q):
  19.     while not q.empty():
  20.         value = q.get()
  21.         answer = autenti(user_name, value)
  22.         if answer:
  23.             print "The value", value, "was correcte!"
  24.  
  25. def get_dict_from_pycharm(lines):
  26.         with open(lines, "rb") as stream:
  27.             data = stream.read().split("\n")
  28.         return data
  29.  
  30.  
  31. def main():
  32.     passwords = get_dict_from_pycharm(lines)
  33.     password_qeue = Queue.Queue()
  34.  
  35.     for p in passwords:
  36.             password_qeue.put(p)
  37.  
  38.     start_time = time()
  39.     my_thread = []
  40.  
  41.     for i in range (number_of_thread):
  42.         t = Thread(target=thread_job, args=(password_qeue,))
  43.         my_thread.append(t)
  44.         t.start()
  45.  
  46.     for t in my_thread:
  47.             t.join()
  48.  
  49.     total_time = time() - start_time
  50.     print "This program took",total_time
  51.  
  52.  
  53. if __name__ == "__main__":
  54.         main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement