Ejemplo de hilos
Código:
"Generar Thread"
#Version Carlos Olvera
import threading
import time
stop = 0
def hola_mundo(nombre):
play=1
while play < 11:
print ("Hola Mundo " + str(play) + nombre)
play=(play+1)
time.sleep(1) #tiempo que duerme el programa
if __name__ == "__main__":
hilos = threading.Thread(target =hola_mundo, args = (" Azul ",) )
hilos.start()
print 'ultima instruccion del main'
Código:
#Livan Lumbreras
"Generar Thread"
import threading
import time
stop = 0
def hola_mundo(nombre):
cont = 0
play = 1
while play == 1:
print ("Hola Mundo" + nombre + str(cont))
time.sleep(1) # tiempo que duerme el programa
cont = cont + 1
if cont == 10:
play = 2
if __name__ == "__main__":
hilos = threading.Thread(target=hola_mundo, args=(" Azul ",))
hilos.start()
print("Hola mundo desde el hilo principal")
Código:
import threading
import time
#Ambrocio isaias
stop = 1
play = 0
def hola_mundo(nombre):
global play, stop
while play == 0:
print ("\nHola mundo" + nombre)
time.sleep(2)
if stop == 1:
break
if __name__ == "__main__":
hilos = threading.Thread(target=hola_mundo, args=(" Azul ",))
hilos.start()
#hilos.join()
stop = input("\nIntroduzca el valor de stop: ")
print "Hola mundo desde el hilo principal"



No hay comentarios:
Publicar un comentario