Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Apr 25 17:34:42 2018
  4.  
  5. @author: STUDENT
  6. """
  7.  
  8. import queue, threading
  9. import random, time
  10. import matplotlib.pyplot as plt
  11.  
  12.  
  13. def losuj(x,nr, out_q):
  14. for i in range(5):
  15. r = random.randint(1,20)
  16. out_q.put(r)
  17. print("wylosowana liczba "+str(r))
  18. print("wylosowana liczba %s" % (str(nr)))
  19. time.sleep(x)
  20. out_q.put(None)
  21. print("zakonczył dzaiłanie"+str(nr))
  22.  
  23.  
  24. def wyniki(in_q):
  25. while True:
  26. n=in_q.get();
  27. if n is None:
  28. print("Zakończona praca")
  29. break
  30. print("wynik: "+str(n))
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. def main():
  38.  
  39. q=queue.Queue()
  40. t1= threading.Thread(target=losuj,args=(4,1,q))
  41. t2= threading.Thread(target=wyniki,args=(q,))
  42. t1.start()
  43. t2.start()
  44.  
  45. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement