diff --git a/py/threads/03.py b/py/threads/03.py new file mode 100644 index 0000000..254b4f8 --- /dev/null +++ b/py/threads/03.py @@ -0,0 +1,22 @@ +import threading +import time +import random + +def tareaUno(): + global Done + time.sleep (random.random()) + if not Done: + print("Tarea realizada") + Done = True + else : + print ("tarea NO REALIZADA") + return + + +Done = False +hilos = list() +for i in range(50): + t = threading.Thread(target=tareaUno) + hilos.append(t) + t.start() +time.sleep(1) \ No newline at end of file diff --git a/py/threads/04.py b/py/threads/04.py new file mode 100644 index 0000000..db2bad4 --- /dev/null +++ b/py/threads/04.py @@ -0,0 +1,38 @@ +import threading +import time +import random + +Done = False +i = 1 +j = 1 + +def tareaUno(): + global Done + global i + if not Done: + print("Tarea %d realizada\n" % i,flush=True) + Done = True + else : + print ("tarea %d NO REALIZADA\n" % i,flush=True) + i +=1 + return + +def tareaDos(): + global Done + global j + Done = False + print("----- %d tareaDos\n" % j,flush=True) + j+=1 + return + +if __name__ == '__main__': + hilos = list() + for i in range(50): + t = threading.Thread(target=tareaUno) + if (i % 5) == 0: + t = threading.Thread(target=tareaDos) + # hilos.append(t) + t.start() + # time.sleep(0.01) + + time.sleep(5) \ No newline at end of file