From 74950f403aae3094c575a62d24725702fc5c5e7c Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Thu, 13 Oct 2022 01:31:45 +0200 Subject: [PATCH 1/4] Add the daemon keyword argument to the Timer constructor --- Lib/threading.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/threading.py b/Lib/threading.py index d030e1243623f9..dd1d9f3cb0b55c 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -1387,8 +1387,8 @@ class Timer(Thread): """ - def __init__(self, interval, function, args=None, kwargs=None): - Thread.__init__(self) + def __init__(self, interval, function, args=None, kwargs=None, *, daemon=None): + Thread.__init__(self, daemon=daemon) self.interval = interval self.function = function self.args = args if args is not None else [] From 38598fba8fc991481c89813f3afb756b4257cd8e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 13 Oct 2022 13:32:06 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2022-10-13-13-32-05.gh-issue-98230.oTb1Az.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2022-10-13-13-32-05.gh-issue-98230.oTb1Az.rst diff --git a/Misc/NEWS.d/next/Library/2022-10-13-13-32-05.gh-issue-98230.oTb1Az.rst b/Misc/NEWS.d/next/Library/2022-10-13-13-32-05.gh-issue-98230.oTb1Az.rst new file mode 100644 index 00000000000000..0cc2bf7d83f49d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-10-13-13-32-05.gh-issue-98230.oTb1Az.rst @@ -0,0 +1 @@ +Add a daemon keyword-only argument to the :func:`threading.Timer` constructor, to pass it to the inherited :func:`Thread` constructor. From 132742403e669bb001f825a90926fc17841a3a57 Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Thu, 13 Oct 2022 15:47:37 +0200 Subject: [PATCH 3/4] Update Misc/NEWS.d/next/Library/2022-10-13-13-32-05.gh-issue-98230.oTb1Az.rst typo..... Co-authored-by: Nikita Sobolev --- .../next/Library/2022-10-13-13-32-05.gh-issue-98230.oTb1Az.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2022-10-13-13-32-05.gh-issue-98230.oTb1Az.rst b/Misc/NEWS.d/next/Library/2022-10-13-13-32-05.gh-issue-98230.oTb1Az.rst index 0cc2bf7d83f49d..d32ae2cc0bcdec 100644 --- a/Misc/NEWS.d/next/Library/2022-10-13-13-32-05.gh-issue-98230.oTb1Az.rst +++ b/Misc/NEWS.d/next/Library/2022-10-13-13-32-05.gh-issue-98230.oTb1Az.rst @@ -1 +1 @@ -Add a daemon keyword-only argument to the :func:`threading.Timer` constructor, to pass it to the inherited :func:`Thread` constructor. +Add a daemon keyword-only argument to the :class:`threading.Timer` constructor, to pass it to the inherited :class:`threading.Thread` constructor. From 825a125785f6173706ef38e08190f5da96128fa0 Mon Sep 17 00:00:00 2001 From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Thu, 13 Oct 2022 15:53:39 +0200 Subject: [PATCH 4/4] Add unit test for Timer's daemon kwarg --- Lib/test/test_threading.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Lib/test/test_threading.py b/Lib/test/test_threading.py index c6649962331464..e6ac0ffdd93fed 100644 --- a/Lib/test/test_threading.py +++ b/Lib/test/test_threading.py @@ -1628,6 +1628,15 @@ def test_init_immutable_default_args(self): timer1.join() timer2.join() + def test_daemon_param(self): + # PR 98231: add the daemon parameter to the Timer argument + t = threading.Timer(1, print) + self.assertFalse(t.daemon) + t = threading.Timer(1, print, daemon=False) + self.assertFalse(t.daemon) + t = threading.Timer(1, print, daemon=True) + self.assertTrue(t.daemon) + def _callback_spy(self, *args, **kwargs): self.callback_args.append((args[:], kwargs.copy())) self.callback_event.set()