mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
Merge #17435: Don't use mutable default values in Timer.
Patch by Denver Coneybeare with some test modifications by me.
This commit is contained in:
commit
5cbf3a0d6e
4 changed files with 37 additions and 17 deletions
|
@ -807,17 +807,17 @@ class Thread:
|
|||
class Timer(Thread):
|
||||
"""Call a function after a specified number of seconds:
|
||||
|
||||
t = Timer(30.0, f, args=[], kwargs={})
|
||||
t = Timer(30.0, f, args=None, kwargs=None)
|
||||
t.start()
|
||||
t.cancel() # stop the timer's action if it's still waiting
|
||||
"""
|
||||
|
||||
def __init__(self, interval, function, args=[], kwargs={}):
|
||||
def __init__(self, interval, function, args=None, kwargs=None):
|
||||
Thread.__init__(self)
|
||||
self.interval = interval
|
||||
self.function = function
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
self.args = args if args is not None else []
|
||||
self.kwargs = kwargs if kwargs is not None else {}
|
||||
self.finished = Event()
|
||||
|
||||
def cancel(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue