38 lines
599 B
Python
38 lines
599 B
Python
import threading
|
|
import time
|
|
import random
|
|
|
|
def tareaUno():
|
|
global Done
|
|
time.sleep (random.random())
|
|
if not Done:
|
|
print("Tarea realizada")
|
|
time.sleep(0.1)
|
|
Done = True
|
|
else :
|
|
print ("tarea NO REALIZADA")
|
|
time.sleep(0.01)
|
|
return
|
|
|
|
def tareaDos():
|
|
global Done
|
|
Done = False
|
|
print("Desactivo")
|
|
|
|
hilos1 = list()
|
|
for i in range(50):
|
|
t = threading.Thread(target=tareaUno)
|
|
hilos1.append(t)
|
|
t.start()
|
|
|
|
Done = False
|
|
tareaUno()
|
|
|
|
hilos2 = list()
|
|
for i in range(5):
|
|
t2 = threading.Thread(target=tareaDos)
|
|
hilos2.append(t2)
|
|
t2.start()
|
|
time.sleep(1)
|
|
|
|
time.sleep(6) |