Add ej03, not complete
This commit is contained in:
parent
fce6fc9073
commit
980019c8b9
|
@ -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)
|
Loading…
Reference in New Issue