38 lines
726 B
Python
38 lines
726 B
Python
import threading
|
|
import time
|
|
import random
|
|
|
|
def tareaUno():
|
|
global Done
|
|
time.sleep(abs(random.gauss(mu=0.0, sigma=1.0)))
|
|
if not Done:
|
|
print("Tarea realizada")
|
|
time.sleep(0.12)
|
|
Done = True
|
|
else :
|
|
print ("tarea NO REALIZADA")
|
|
time.sleep(0.05)
|
|
return
|
|
|
|
|
|
def desactivar():
|
|
global Done
|
|
while True:
|
|
time.sleep(abs(random.gauss(mu=0.0, sigma=1.0)))
|
|
if Done:
|
|
Done = False
|
|
print("Desactivo")
|
|
|
|
if all(not t.is_alive() for t in hilos):
|
|
break
|
|
|
|
Done = False
|
|
hilos = list()
|
|
for i in range(50):
|
|
t = threading.Thread(target=tareaUno)
|
|
hilos.append(t)
|
|
t.start()
|
|
|
|
desbloqueo_thread = threading.Thread(target=desactivar)
|
|
desbloqueo_thread.start()
|