Add ej03, not complete

This commit is contained in:
Dennis Eckerskorn 2024-10-15 19:14:32 +02:00
parent fce6fc9073
commit 980019c8b9
1 changed files with 38 additions and 0 deletions

38
ejercicios_hilos/ej03.py Normal file
View File

@ -0,0 +1,38 @@
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)