commit 9c08e3c0ed6b977a2c689ed19a8edc6c6dfe8e95 Author: LuisCorGon Date: Fri Dec 15 19:00:51 2023 +0100 proyecto simulacion terminado diff --git a/simulacion.py b/simulacion.py new file mode 100644 index 0000000..2d54234 --- /dev/null +++ b/simulacion.py @@ -0,0 +1,99 @@ +import threading +import time + +def hilo1_1(): + print("Hilo1_1 iniciado") + time.sleep(3) + print("Hilo1_1 terminado en 3 segundos") + hilo1_3_t = threading.Thread(target=hilo1_3) + hilo1_3_t.start() + hilo1_4_t = threading.Thread(target=hilo1_4) + hilo1_4_t.start() + hilo1_3_t.join() + hilo1_4_t.join() + hilo3_7_t = threading.Thread(target=hilo3_7) + hilo3_7_t.start() + +def hilo1_3(): + print("Hilo1_3 iniciado") + time.sleep(4) + print("Hilo1_3 terminado en 4 segundos") + +def hilo1_4(): + print("Hilo1_4 iniciado") + time.sleep(4) + print("Hilo1_4 terminado en 4 segundos") + hilo4_7_t = threading.Thread(target=hilo4_7) + hilo4_7_t.start() + + +def hilo3_7(): + print("Hilo3_7 iniciado") + time.sleep(3) + print("Hilo3_7 terminado en 3 segundos") + + +def hilo1_2(): + print("Hilo1_2 iniciado") + time.sleep(2) + print("Hilo1_2 terminado en 2 segundos") + hilo2_4_t = threading.Thread(target=hilo2_4) + hilo2_4_t.start() + hilo2_4_t.join() + +def hilo2_4(): + print("Hilo2_4 iniciado") + time.sleep(3) + print("Hilo2_4 terminado en 3 segundos") + +def hilo4_7(): + print("Hilo4_7 iniciado") + time.sleep(4) + print("Hilo4_7 terminado en 4 segundos") + hilo7_8_t = threading.Thread(target=hilo7_8) + hilo7_8_t.start() + +def hilo1_5(): + print("Hilo1_5 iniciado") + time.sleep(6) + print("Hilo1_5 terminado en 6 segundos") + hilo5_6_t = threading.Thread(target=hilo5_6) + hilo5_6_t.start() + hilo5_6_t.join() # Esperar a que hilo3_1 termine + hilo6_8_t = threading.Thread(target=hilo6_8) + hilo6_8_t.start() + hilo6_8_t.join() + +def hilo5_6(): + print("Hilo5_6 iniciado") + time.sleep(5) + print("Hilo5_6 terminado en 5 segundos") + +def hilo6_8(): + print("Hilo6_8 iniciado") + time.sleep(4) + print("Hilo6_8 terminado en 4 segundos") + +def hilo7_8(): + print("Hilo7_8 iniciado") + time.sleep(2) + print("Hilo7_8 terminado en 2 segundos") + +print("INICIO") +inicio = time.time() +hilo1_1_t = threading.Thread(target=hilo1_1) +hilo1_1_t.start() +hilo1_2_t = threading.Thread(target=hilo1_2) +hilo1_2_t.start() +hilo1_5_t = threading.Thread(target=hilo1_5) +hilo1_5_t.start() + +hilo1_1_t.join() +hilo1_2_t.join() +hilo1_5_t.join() +final = time.time() +tiempo_total = final - inicio +print("FINAL") +print("EL PROYECTO HA TARDADO EN FINALIZAR: ", int(tiempo_total), "segundos") + +