From f7486171bc68415970c687b521acd50d2f42bb5d Mon Sep 17 00:00:00 2001 From: Javier Date: Mon, 3 Nov 2025 20:52:45 +0100 Subject: [PATCH] 02.py --- py/threads/01.py | 31 +++++++++++++++++++++---------- py/threads/02.py | 13 +++++++++++++ 2 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 py/threads/02.py diff --git a/py/threads/01.py b/py/threads/01.py index 6abf0eb..721501f 100644 --- a/py/threads/01.py +++ b/py/threads/01.py @@ -1,15 +1,26 @@ import threading +import random +import time +def hilo1(): + time.sleep(random.uniform(0, 1.5)) + print("Soy el Hilo 1 y primero") -def Hilo2(): - print ('Soy el hilo 2\n') - t3 = threading.Thread(target=Hilo3) - t3.start() +def hilo2(): + time.sleep(random.uniform(0, 1.5)) + print("Soy el hilo 2") -def Hilo3(): - print ('Soy el hilo 3 y Ășltimo\n') +def hilo3(): + time.sleep(random.uniform(0, 1.5)) + print("Soy el hilo 3 y Ășltimo") -t2 = threading.Thread(target=Hilo2) - -t2.start() -print ("Soy el Hilo 1 y primero\n") \ No newline at end of file +if __name__ == "__main__": + t1 = threading.Thread(target=hilo1) + t2 = threading.Thread(target=hilo2) + t3 = threading.Thread(target=hilo3) + t1.start() + t2.start() + t3.start() + t1.join() + t2.join() + t3.join() \ No newline at end of file diff --git a/py/threads/02.py b/py/threads/02.py new file mode 100644 index 0000000..4a21cb0 --- /dev/null +++ b/py/threads/02.py @@ -0,0 +1,13 @@ +import threading + +def escribeY(): + for i in range(1000): + print (".", end="",flush=True) + return + +print ("INICIO") +t = threading.Thread(target=escribeY) +t.start() + +for i in range(1000): + print ("-", end="",flush=True) \ No newline at end of file