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

207
Views
Python threading timer initial daemon

This code is not working......

self._thread = threading.Timer(interval=2, 
                               function=self._sendRequestState, 
                               args=(self._lockState,), 
                               daemon=True).start()

So I should write down like this..

self._thread = threading.Timer(interval=2, 
                               function=self._sendRequestState, 
                               args=(self._lockState,))
self._thread.daemon = True
self._thread.start()

But the Timer class has Thread.__init__, Thread.__init__ has "daemon" for input parameter. I don't have any idea why it doesn't work...

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can find the source code of that threading.Thread() constructor here (of cpython, the most common python implementation):

def __init__(self, interval, function, args=None, kwargs=None):
    Thread.__init__(self)
    self.interval = interval
    self.function = function
    self.args = args if args is not None else []
    self.kwargs = kwargs if kwargs is not None else {}
    self.finished = Event()

If you pass daemon=True into it, that will be put in kwargs, but as you can see in the code, nothing happens with it. So yes, you're correct, you'll have to set the daemon attribute after creating it (and before calling start(). There seems to be no option to set it directly when constructing the Timer.

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!