Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 750163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:31:11+00:00 2026-05-14T14:31:11+00:00

from threading import Timer def hello(): print hello, world t = Timer(30.0, hello) t.start()

  • 0
from threading import Timer

def hello():
    print "hello, world"

t = Timer(30.0, hello)
t.start()

This code only fires the timer once.

How can I make the timer run forever?

Thanks,

updated

this is right :

import time,sys

def hello():
    while True:
        print "Hello, Word!"
        sys.stdout.flush()
        time.sleep(2.0)
hello()

and this:

from threading import Timer

def hello():
    print "hello, world"
    sys.stdout.flush()
    t = Timer(2.0, hello)
    t.start()

t = Timer(2.0, hello)
t.start()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:31:11+00:00Added an answer on May 14, 2026 at 2:31 pm

    A threading.Timer executes a function once. That function can “run forever” if you wish, for example:

    import time
    
    def hello():
        while True:
            print "Hello, Word!"
            time.sleep(30.0)
    

    Using multiple Timer instances would consume substantial resources with no real added value. If you want to be non-invasive to the function you’re repeating every 30 seconds, a simple way would be:

    import time
    
    def makerepeater(delay, fun, *a, **k):
        def wrapper(*a, **k):
            while True:
                fun(*a, **k)
                time.sleep(delay)
        return wrapper
    

    and then schedule makerepeater(30, hello) instead of hello.

    For more sophisticated operations, I recommend standard library module sched.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried this code: import threading def hello(arg, kargs): print(arg) t = threading.Timer(2, hello,
why this code does not work? from threading import Timer def delayed(seconds): def decorator(f):
I have this class: from threading import Thread import time class Timer(Thread): def __init__(self,
from threading import Thread import time print 'start of script' class MyThread(Thread): def run(self):
Why doesn't this code act threaded? (Please see the output.) import time from threading
Say I derive from threading.Thread: from threading import Thread class Worker(Thread): def start(self): self.running
From this context: import itertools lines = itertools.cycle(open('filename')) I'm wondering how I can implement
On Ubuntu I compiled sbcl 1.0.35 with threading. I can happily use sbcl from
using code from this site: http://www.saltycrane.com/blog/2008/09/simplistic-python-thread-example/ The code is import time from threading import
import os import sys, urllib2, urllib import re import time from threading import Thread

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.