This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: threading.Timer: Constructor does not handle args correctly
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: dominikush, effbot
Priority: normal Keywords:

Created on 2005-11-28 19:10 by dominikush, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg26933 - (view) Author: dominikush (dominikush) Date: 2005-11-28 19:10
The constructor of threading.Timer does not correctly
handle arguments passed to it, see example given. I
noted the bug in Python 2.4.1 and checked it also for
Python 2.4.2:

>>> def test(*args,**kwds): print "test: args
=",args,"and kwds =",kwds
...
>>> import threading
>>> t = threading.Timer(2,test,"hello")
>>> t.start()
>>> test: args = ('h', 'e', 'l', 'l', 'o') and kwds = {}

Proposed bug fix in threading.Timer.__init__:

    def __init__(self, interval, function, args=[],
kwargs={}): # bug
    def __init__(self, interval, function, *args,
**kwargs):    # correction

After proposed correction, rerun of test results in:

>>> t.start()
>>> test: args = ('hallo',) and kwds = {}

msg26934 - (view) Author: Fredrik Lundh (effbot) * (Python committer) Date: 2005-11-29 11:11
Logged In: YES 
user_id=38376

The implemented behaviour is the documented behaviour (it's
the same for both Thread and Timer).  You're not supposed to
"call" the Thread constructor; you're supposed to pass in
the arguments using keyword arguments.  See the library
reference for details.
History
Date User Action Args
2022-04-11 14:56:14adminsetgithub: 42638
2005-11-28 19:10:28dominikushcreate