Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!