Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
19aeb439
Kaydet (Commit)
19aeb439
authored
Mar 30, 2013
tarafından
R David Murray
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #17435: Don't use mutable default values in Timer.
Patch by Denver Coneybeare with some test modifications by me.
üst
8028a5cf
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
17 deletions
+37
-17
threading.rst
Doc/library/threading.rst
+3
-1
test_threading.py
Lib/test/test_threading.py
+27
-12
threading.py
Lib/threading.py
+4
-4
NEWS
Misc/NEWS
+3
-0
No files found.
Doc/library/threading.rst
Dosyayı görüntüle @
19aeb439
...
...
@@ -839,10 +839,12 @@ For example::
t.start() # after 30 seconds, "hello, world" will be printed
.. class:: Timer(interval, function, args=
[], kwargs={}
)
.. class:: Timer(interval, function, args=
None, kwargs=None
)
Create a timer that will run *function* with arguments *args* and keyword
arguments *kwargs*, after *interval* seconds have passed.
If *args* is None (the default) then an empty list will be used.
If *kwargs* is None (the default) then an empty dict will be used.
.. versionchanged:: 3.3
changed from a factory function to a class.
...
...
Lib/test/test_threading.py
Dosyayı görüntüle @
19aeb439
...
...
@@ -786,6 +786,32 @@ class ThreadingExceptionTests(BaseTestCase):
self
.
assertEqual
(
p
.
returncode
,
0
,
"Unexpected error: "
+
stderr
.
decode
())
self
.
assertEqual
(
data
,
expected_output
)
class
TimerTests
(
BaseTestCase
):
def
setUp
(
self
):
BaseTestCase
.
setUp
(
self
)
self
.
callback_args
=
[]
self
.
callback_event
=
threading
.
Event
()
def
test_init_immutable_default_args
(
self
):
# Issue 17435: constructor defaults were mutable objects, they could be
# mutated via the object attributes and affect other Timer objects.
timer1
=
threading
.
Timer
(
0.01
,
self
.
_callback_spy
)
timer1
.
start
()
self
.
callback_event
.
wait
()
timer1
.
args
.
append
(
"blah"
)
timer1
.
kwargs
[
"foo"
]
=
"bar"
self
.
callback_event
.
clear
()
timer2
=
threading
.
Timer
(
0.01
,
self
.
_callback_spy
)
timer2
.
start
()
self
.
callback_event
.
wait
()
self
.
assertEqual
(
len
(
self
.
callback_args
),
2
)
self
.
assertEqual
(
self
.
callback_args
,
[((),
{}),
((),
{})])
def
_callback_spy
(
self
,
*
args
,
**
kwargs
):
self
.
callback_args
.
append
((
args
[:],
kwargs
.
copy
()))
self
.
callback_event
.
set
()
class
LockTests
(
lock_tests
.
LockTests
):
locktype
=
staticmethod
(
threading
.
Lock
)
...
...
@@ -815,16 +841,5 @@ class BoundedSemaphoreTests(lock_tests.BoundedSemaphoreTests):
class
BarrierTests
(
lock_tests
.
BarrierTests
):
barriertype
=
staticmethod
(
threading
.
Barrier
)
def
test_main
():
test
.
support
.
run_unittest
(
LockTests
,
PyRLockTests
,
CRLockTests
,
EventTests
,
ConditionAsRLockTests
,
ConditionTests
,
SemaphoreTests
,
BoundedSemaphoreTests
,
ThreadTests
,
ThreadJoinOnShutdown
,
ThreadingExceptionTests
,
BarrierTests
,
)
if
__name__
==
"__main__"
:
test_
main
()
unittest
.
main
()
Lib/threading.py
Dosyayı görüntüle @
19aeb439
...
...
@@ -802,17 +802,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
):
...
...
Misc/NEWS
Dosyayı görüntüle @
19aeb439
...
...
@@ -15,6 +15,9 @@ Core and Builtins
Library
-------
- Issue #17435: threading.Timer'
s
__init__
method
no
longer
uses
mutable
default
values
for
the
args
and
kwargs
parameters
.
-
Issue
#
17526
:
fix
an
IndexError
raised
while
passing
code
without
filename
to
inspect
.
findsource
().
Initial
patch
by
Tyler
Doyle
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment