Advertisement
LightProgrammer000

Threading

Aug 2nd, 2021
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. # Biblioteca
  2. from time import sleep
  3. from threading import Thread
  4.  
  5. # Funcao: Carrinho 1
  6. def carrinho_1(velocidade, tempo):
  7.  
  8.     # Variaveis
  9.     distancia = 0
  10.  
  11.     # Estrutura de repeticao
  12.     while distancia <= 300:
  13.  
  14.         # Mensagem
  15.         print(" # Carrinho 1 [distancia]: ", str(distancia))
  16.  
  17.         # Incremento
  18.         distancia += velocidade * tempo
  19.         sleep(2.0)
  20.  
  21.     print("\033[01;34m\n - Carrinho 1 chegou \033[01;37m")
  22.  
  23. # Funcao: Carrinho 1
  24. def carrinho_2(velocidade, tempo):
  25.  
  26.     # Variaveis
  27.     distancia = 0
  28.  
  29.     # Estrutura de repeticao
  30.     while distancia <= 300:
  31.  
  32.         # Mensagem
  33.         print(" # Carrinho 2 [distancia]: ", str(distancia))
  34.         print("")
  35.  
  36.         # Incremento
  37.         distancia += velocidade * tempo
  38.         sleep(2.0)
  39.  
  40.     print("\033[01;34m\n - Carrinho 2 chegou \033[01;37m")
  41.  
  42. # Principal
  43. def main():
  44.  
  45.     # Threads
  46.     thread_Carrinho1 = Thread(target=carrinho_1, args=[10, 3])
  47.     thread_Carrinho2 = Thread(target=carrinho_2, args=[10, 4])
  48.  
  49.     # Start
  50.     thread_Carrinho1.start()
  51.     thread_Carrinho2.start()
  52.  
  53. # Execucao
  54. if __name__ == '__main__':
  55.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement