Exemplo 1 Threads
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import threading
|
||||
import time
|
||||
|
||||
#Função que será executada pela thread
|
||||
def executar (nome_thread, n_iteracoes):
|
||||
for i in range(n_iteracoes):
|
||||
print (f"Nome da thread: {nome_thread}")
|
||||
time.sleep(2) #Parar por 2s
|
||||
|
||||
t1 = threading.Thread(target=executar,args=["Thread1",15])
|
||||
t2 = threading.Thread(target=executar,args=["Thread2",10])
|
||||
|
||||
t1.start()
|
||||
t2.start()
|
||||
|
||||
t1.join()
|
||||
t2.join()
|
||||
|
||||
print("Final da thread principal!")
|
||||
Reference in New Issue
Block a user