diff --git a/Python/pt1/p1.2.py b/Python/pt1/p1.2.py new file mode 100644 index 0000000..aaa7d36 --- /dev/null +++ b/Python/pt1/p1.2.py @@ -0,0 +1,17 @@ +from multiprocessing import Process +import os +def hijo(): + print("Padre: %d, Hijo: %d\n" % ( os.getppid(),os.getpid())) + os._exit(0) + +def padre(): + while True: + p = Process(target=hijo) + p.start() + print ("\nNuevo hijo creado " , p.pid) + p.join() + reply = input("Pulsa 's' si quieres crear un nuevo proceso\n") + if reply != 's': + break +if __name__ == '__main__': + padre() \ No newline at end of file diff --git a/Python/p1.py b/Python/pt1/p1.py similarity index 100% rename from Python/p1.py rename to Python/pt1/p1.py diff --git a/Python/pt1/p2.py b/Python/pt1/p2.py new file mode 100644 index 0000000..6e2ca25 --- /dev/null +++ b/Python/pt1/p2.py @@ -0,0 +1,12 @@ +import subprocess +def iniciaPrograma(): + try: + SW_SHOWMAXIMIZED = 3 + info = subprocess.STARTUPINFO() + info.dwFlags |= subprocess.STARTF_USESHOWWINDOW + info.wShowWindow = SW_SHOWMAXIMIZED + subprocess.Popen('Notepad.exe', startupinfo=info) + except subprocess.CalledProcessError as e: + print(e.output) +iniciaPrograma() +input("Pulsa una tecla para terminar la ejecución") \ No newline at end of file diff --git a/Python/pt1/p5.py b/Python/pt1/p5.py new file mode 100644 index 0000000..c6478c5 --- /dev/null +++ b/Python/pt1/p5.py @@ -0,0 +1,16 @@ +import subprocess +import time + +def CrearProceso(): + try: + """SW_SHOWMAXIMIZED = 3 + info = subprocess.STARTUPINFO() + info.dwFlags |= subprocess.STARTF_USESHOWWINDOW + info.wShowWindow = SW_SHOWMAXIMIZED""" + proc = subprocess.Popen('notepad.exe') + return proc + except subprocess.CalledProcessError as e: + print(e.output) +p = CrearProceso() +print ("El PID de este proceso es: " + str(p.pid)) +time.sleep(5) \ No newline at end of file diff --git a/Python/variable.py b/Python/pt1/variable.py similarity index 100% rename from Python/variable.py rename to Python/pt1/variable.py diff --git a/Python/pt2/eje2.py b/Python/pt2/eje2.py new file mode 100644 index 0000000..ca9670d --- /dev/null +++ b/Python/pt2/eje2.py @@ -0,0 +1,12 @@ +import threading +def actividad(): + print ("Escribo desde un hilo") + return +print ("INICIO") + +hilos = list() +for i in range(50): + t = threading.Thread(target=actividad) + hilos.append(t) + t.start() +print ("ESCRIBO EN PRINCIPAL") \ No newline at end of file diff --git a/Python/pt2/hilo.py b/Python/pt2/hilo.py new file mode 100644 index 0000000..af21e18 --- /dev/null +++ b/Python/pt2/hilo.py @@ -0,0 +1,9 @@ +import threading; + +def Saludo(): + print('hola') + +t=threading.Thread(target=Saludo) + +t.start() +print('hola') \ No newline at end of file diff --git a/Python/pt2/paralel.py b/Python/pt2/paralel.py new file mode 100644 index 0000000..a4bd65c --- /dev/null +++ b/Python/pt2/paralel.py @@ -0,0 +1,10 @@ +import threading +def escribeY(): + for i in range(100): + print ("y", end="") + return +print ("INICIO") +t = threading.Thread(target=escribeY) +t.start() +for i in range(100): + print ("X", end="") \ No newline at end of file diff --git a/Python/pt2/paralel2.py b/Python/pt2/paralel2.py new file mode 100644 index 0000000..fb5d56b --- /dev/null +++ b/Python/pt2/paralel2.py @@ -0,0 +1,16 @@ +import threading +import time +import random +def tareaUno(): + global Realizado + #time.sleep (random.random()) + if not Realizado: + print("Tarea realizada") + Realizado = True + return + +Realizado = False +t = threading.Thread(target=tareaUno) +t.start() +tareaUno() +time.sleep(1) \ No newline at end of file diff --git a/Python/pt2/paralel3.py b/Python/pt2/paralel3.py new file mode 100644 index 0000000..19d4dbb --- /dev/null +++ b/Python/pt2/paralel3.py @@ -0,0 +1,20 @@ +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() +tareaUno() +time.sleep(1) \ No newline at end of file diff --git a/Python/pt2/paralel4.py b/Python/pt2/paralel4.py new file mode 100644 index 0000000..bc40aa2 --- /dev/null +++ b/Python/pt2/paralel4.py @@ -0,0 +1,13 @@ +import logging +import threading +import time +def thread_Apellido(name): + print (name + " Rodríguez") + #print (name + " Rodríguez\n") + +nombres = ["Julio", "Javier", "Eladio", "Jose", "Manuel"] +hilos = list() +for n in nombres: + t = threading.Thread(target=thread_Apellido, args=(n,)) + hilos.append(t) + t.start() \ No newline at end of file diff --git a/Python/pt2/paralelEjer1.py b/Python/pt2/paralelEjer1.py new file mode 100644 index 0000000..8ce5a9f --- /dev/null +++ b/Python/pt2/paralelEjer1.py @@ -0,0 +1,24 @@ +import threading + +def TriangleArea(base,hight): + print((base * hight)/2) + +def RectangleArea(width,hight): + print(width*hight) + +def RectangleDosArea(width,hight): + print(width*hight) + +def TriangleDosArea(base,hight): + print((base * hight)/2) + + +tr = threading.Thread(TriangleArea(10,12)) +tr2 = threading.Thread(TriangleDosArea(2,5)) +rect = threading.Thread(RectangleArea(8,12)) +rect2 = threading.Thread(RectangleDosArea(6,5)) + +tr.start +tr2.start +rect.start +rect2.start