Sintaxis del programa:
import threading
import time
def hola_mundo(nombre):
cont = 0
play = 1
while play == 1:
print ('Hola mundo '+nombre)
time.sleep(1)
cont = cont + 1
if cont == 10:
play = 2
if __name__ == '__main__':
hilos=threading.Thread(target=hola_mundo, args=('Lyvan',))
hilos.start()
Sintaxis del programa mejorado por Ambrocio:
import threading
import time
stop = 0
play = 1
def hola_mundo(nombre):
global play, stop
while play == 1:
print ('Hola mundo '+nombre)
time.sleep(1)
if stop == 1:
break
if __name__ == '__main__':
hilos=threading.Thread(target=hola_mundo, args=('Lyvan',))
hilos.start()
stop = input("Introduce el valor de stop")
print "Hola mundo desde el hilo principal"
No hay comentarios.:
Publicar un comentario