1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import threading def contador(n): for i in range(n): print("Hilo 1: ", i) def mensaje(): print("Hilo 2: Hola desde el segundo hilo") # Crear dos hilos t1 = threading.Thread(target=contador, args=(10,)) t2 = threading.Thread(target=mensaje) # Iniciar hilo 1 y esperar a que termine t1.start() t1.join() # Iniciar hilo 2 t2.start() t2.join() print("Los hilos han terminado") |