Advertisement
Rodripelto

Hilos

Jul 11th, 2021
1,088
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. import threading as th
  2. import time as tm
  3.  
  4. def proceso1(e):
  5.   print("Inicio Proceso 1")
  6.   for i in range(100000):
  7.     e.wait()
  8.     print(i)
  9.  
  10. def tiempo(e):
  11.   print("Activo tiempo")
  12.   print("Espera 5 s antes de iniciar")
  13.   e.clear()
  14.   tm.sleep(5)
  15.   print("Termina espera")
  16.   tm.sleep(1)
  17.   e.set()
  18.   tm.sleep(5)
  19.   e.clear()
  20.   print("Pauso de nuevo")
  21.   tm.sleep(5)
  22.   print("Al final")
  23.   tm.sleep(1)
  24.   e.set()
  25.  
  26. e= th.Event()
  27. ptiempi= th.Thread(target= tiempo,args= (e,))
  28. pprincipal = th.Thread(target= proceso1,args= (e,))
  29. ptiempi.start()
  30. pprincipal.start()
  31. ptiempi.join()
  32. pprincipal.join()
  33.  
  34. import multiprocessing as pr
  35. e= pr.Event()
  36. ptiemp= pr.Process(target= tiempo,args= (e,))
  37. pprincipal1 = pr.Process(target= proceso1,args= (e,))
  38. ptiemp.start()
  39. pprincipal1.start()
  40. ptiemp.join()
  41. pprincipal1.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement