This commit is contained in:
Javier 2025-11-03 20:52:45 +01:00
parent bfb9b6b773
commit f7486171bc
2 changed files with 34 additions and 10 deletions

View File

@ -1,15 +1,26 @@
import threading import threading
import random
import time
def hilo1():
time.sleep(random.uniform(0, 1.5))
print("Soy el Hilo 1 y primero")
def Hilo2(): def hilo2():
print ('Soy el hilo 2\n') time.sleep(random.uniform(0, 1.5))
t3 = threading.Thread(target=Hilo3) print("Soy el hilo 2")
t3.start()
def Hilo3(): def hilo3():
print ('Soy el hilo 3 y último\n') time.sleep(random.uniform(0, 1.5))
print("Soy el hilo 3 y último")
t2 = threading.Thread(target=Hilo2)
if __name__ == "__main__":
t1 = threading.Thread(target=hilo1)
t2 = threading.Thread(target=hilo2)
t3 = threading.Thread(target=hilo3)
t1.start()
t2.start() t2.start()
print ("Soy el Hilo 1 y primero\n") t3.start()
t1.join()
t2.join()
t3.join()

13
py/threads/02.py Normal file
View File

@ -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)