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 4265554
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:38:24+00:00 2026-05-21T06:38:24+00:00

I want to run a code that runs a function with a parameter (eg.

  • 0

I want to run a code that runs a function with a parameter (eg. greet(h)) every 5 seconds. I tried using threading but it doesn’t work. It executes just once. See the code below and the errors:

import threading

oh_hi = "Hi guys"

def greeting(hello):
    print "%s" % hello



threading.Timer(1, greeting(oh_hi)).start()

Error shown below:

> >>> ================================ RESTART
> ================================
> >>>  Hi guys
> >>> Exception in thread Thread-1: Traceback (most recent call last):  
> File "C:\Python27\lib\threading.py",
> line 530, in __bootstrap_inner
>     self.run()   File "C:\Python27\lib\threading.py", line
> 734, in run
>     self.function(*self.args, **self.kwargs) TypeError: 'NoneType' object is not callable

Kindly assist.

Thanks

  • 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-21T06:38:25+00:00Added an answer on May 21, 2026 at 6:38 am

    As others have pointed out, the error is because you’re not passing the proper arguments to the threading.Timer() method. Correcting that will run your function, once, after 5 seconds. There are a number of ways to get it to repeat.

    An object-oriented approach would be to derive a new threading.Thread subclass. While it would be possible to create one that does specifically what you want — namely print "%s" % hello — it’s only slightly more difficult to craft a more generic, parameterized, subclass that will call a function passed to it during its instantiation (just like threading.Timer()). This is illustrated below:

    import threading
    import time
    
    class RepeatEvery(threading.Thread):
        def __init__(self, interval, func, *args, **kwargs):
            threading.Thread.__init__(self)
            self.interval = interval  # seconds between calls
            self.func = func          # function to call
            self.args = args          # optional positional argument(s) for call
            self.kwargs = kwargs      # optional keyword argument(s) for call
            self.runable = True
        def run(self):
            while self.runable:
                self.func(*self.args, **self.kwargs)
                time.sleep(self.interval)
        def stop(self):
            self.runable = False
    
    def greeting(hello):
        print hello
    
    thread = RepeatEvery(3, greeting, "Hi guys")
    print "starting"
    thread.start()
    thread.join(21)  # allow thread to execute a while...
    thread.stop()
    print 'stopped'
    

    Output:

    # starting
    # Hi guys
    # Hi guys
    # Hi guys
    # Hi guys
    # Hi guys
    # Hi guys
    # Hi guys
    # stopped
    

    Besides overriding the base threading.Thread class’s __init__() and run() methods, a stop() method was added to allow the thread to be terminated when desired. I also simplified the print "%s" % hello in your greeting() function to just print hello.

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

Sidebar

Related Questions

I want to run Prolog code using Java. I found some engines, but the
I want to package a piece of code that absolutely must run on Java
I want this for some conditional compilation code that will run in all IE's
I want to run code which needs boost libraries. I built it using CMake.
Using Rails 3.0.7, REE 1.8.7. I want to run code (specifically, Garbage Collection) in
I want to run the following jquery code on every page in my website.
I have a few lines of code that I want to run asynchronously in
I have a function that runs some fairly generic code that does a lot
I have the following function that I want to run on page load and
I want to run a function when the page is loaded, but I don’t

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.