[ python-Bugs-1368515 ] threading.Timer: Constructor does not handle args correctly

SourceForge.net noreply at sourceforge.net
Tue Nov 29 12:11:42 CET 2005


Bugs item #1368515, was opened at 2005-11-28 20:10
Message generated for change (Settings changed) made by effbot
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1368515&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Not a Bug
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: dominikush (dominikush)
Assigned to: Nobody/Anonymous (nobody)
Summary: threading.Timer: Constructor does not handle args correctly

Initial Comment:
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 = {}



----------------------------------------------------------------------

Comment By: Fredrik Lundh (effbot)
Date: 2005-11-29 12:11

Message:
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.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1368515&group_id=5470


More information about the Python-bugs-list mailing list