From 71f2eeed0ed28896a23fa4c4d6e39186e6eacda9 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Sat, 15 Feb 2025 07:45:27 +0000 Subject: [PATCH 1/3] fix run_forever --- Lib/asyncio/base_events.py | 2 +- Lib/test/test_asyncio/test_events.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py index ed852421e44212..546361f80b1f47 100644 --- a/Lib/asyncio/base_events.py +++ b/Lib/asyncio/base_events.py @@ -671,8 +671,8 @@ def _run_forever_cleanup(self): def run_forever(self): """Run until stop() is called.""" + self._run_forever_setup() try: - self._run_forever_setup() while True: self._run_once() if self._stopping: diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py index 3838993fa8c6a9..35069608d8163a 100644 --- a/Lib/test/test_asyncio/test_events.py +++ b/Lib/test/test_asyncio/test_events.py @@ -3004,6 +3004,22 @@ async def main(): self.loop.run_until_complete(main()), 'hello') + def test_get_running_loop_already_running(self): + async def main(): + running_loop = asyncio.get_running_loop() + loop = asyncio.new_event_loop() + try: + loop.run_forever() + except RuntimeError: + pass + else: + self.fail("RuntimeError not raised") + + self.assertIs(asyncio.get_running_loop(), running_loop) + + self.loop.run_until_complete(main()) + + def test_get_event_loop_returns_running_loop(self): class TestError(Exception): pass From 55a48e1c881ab35609d686f01214846e8711c6ad Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Sat, 15 Feb 2025 07:50:42 +0000 Subject: [PATCH 2/3] =?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/2025-02-15-07-50-37.gh-issue-130145.I0CkV0.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-02-15-07-50-37.gh-issue-130145.I0CkV0.rst diff --git a/Misc/NEWS.d/next/Library/2025-02-15-07-50-37.gh-issue-130145.I0CkV0.rst b/Misc/NEWS.d/next/Library/2025-02-15-07-50-37.gh-issue-130145.I0CkV0.rst new file mode 100644 index 00000000000000..a8c5542dca4856 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-02-15-07-50-37.gh-issue-130145.I0CkV0.rst @@ -0,0 +1 @@ +Fix :meth:`asyncio.AbstractEventloop.run_forever` when another loop is already running. From afb692a4da68701f57738f631f2efee206e00852 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Sat, 15 Feb 2025 13:25:33 +0530 Subject: [PATCH 3/3] Update Misc/NEWS.d/next/Library/2025-02-15-07-50-37.gh-issue-130145.I0CkV0.rst --- .../next/Library/2025-02-15-07-50-37.gh-issue-130145.I0CkV0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2025-02-15-07-50-37.gh-issue-130145.I0CkV0.rst b/Misc/NEWS.d/next/Library/2025-02-15-07-50-37.gh-issue-130145.I0CkV0.rst index a8c5542dca4856..9c8c469bff5663 100644 --- a/Misc/NEWS.d/next/Library/2025-02-15-07-50-37.gh-issue-130145.I0CkV0.rst +++ b/Misc/NEWS.d/next/Library/2025-02-15-07-50-37.gh-issue-130145.I0CkV0.rst @@ -1 +1 @@ -Fix :meth:`asyncio.AbstractEventloop.run_forever` when another loop is already running. +Fix :meth:`!asyncio.AbstractEventloop.run_forever` when another loop is already running.