Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

187
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda