Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
Is it possible to run threads in while loop

I am trying to run a thread in while loop but I am getting the error RuntimeError: threads can only be started once kindly suggest a way to fix this

import sys
import threading
import time

import keyboard


def hd():
    time.sleep(1)
    print("hello")


cc = threading.Thread(target=hd)

while True:
    time.sleep(3)
    if keyboard.is_pressed("q"):
        print("Q is pressed")
        sys.exit()
    else:
        if not cc.is_alive():
            cc.start()
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Check this post out: link. It provides some good insight into your question.

Threads are basically destroyed after they have completed. Editing your else statement to something like this might accomplish the task at hand:

if not cc.is_alive():
        cc = threading.Thread(target=hd)
        cc.start()
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda