Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-110771: Decompose run_forever() into parts#110773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gvanrossum merged 12 commits intopython:mainfromfreakboy3742:decomposed-event-loop
Oct 13, 2023
Merged
Changes from1 commit
Commits
Show all changes
12 commits
Select commitHold shift + click to select a range
a0c1fde
Decompose run_forever() into parts to allow external usage.
freakboy3742Oct 12, 2023
67bfc8f
📜🤖 Added by blurb_it.
blurb-it[bot]Oct 13, 2023
3dcf97b
Add docs for run_forever_setup and run_forever_cleanup.
freakboy3742Oct 13, 2023
35271dc
Ensure failures during setup don't prevent cleanup.
freakboy3742Oct 13, 2023
6672f68
Add tests for custom event loop implementation.
freakboy3742Oct 13, 2023
54349c3
Store pre-event loop state as a protected variable.
freakboy3742Oct 13, 2023
e6226a5
Add a missing super() call.
freakboy3742Oct 13, 2023
23852d0
Improvements to docs, including a prototype custom event loop.
freakboy3742Oct 13, 2023
e7f892e
Correct prototype of run_forever_cleanup on Windows Proactor.
freakboy3742Oct 13, 2023
f944944
Merge branch 'main' into decomposed-event-loop
freakboy3742Oct 13, 2023
3143126
Keep the setup/cleanup methods as protected API.
freakboy3742Oct 13, 2023
1b3e3d8
Merge branch 'main' into decomposed-event-loop
freakboy3742Oct 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Add tests for custom event loop implementation.
  • Loading branch information
@freakboy3742
freakboy3742 committedOct 13, 2023
commit6672f6875eee9d281889f1fc34180c913f4faed2
37 changes: 37 additions & 0 deletionsLib/test/test_asyncio/test_base_events.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -922,6 +922,43 @@ def test_run_forever_pre_stopped(self):
self.loop.run_forever()
self.loop._selector.select.assert_called_once_with(0)

def test_custom_run_forever_integration(self):
# Test that the run_forever_setup() and run_forever_cleanup() primitives
# can be used to implement a custom run_forever loop.
self.loop._process_events = mock.Mock()

count = 0

def callback():
nonlocal count
count += 1

self.loop.call_soon(callback)

# Set up the custom event loop
orig_state = self.loop.run_forever_setup()

# Confirm the loop has been started
self.assertEqual(asyncio.get_running_loop(), self.loop)
self.assertTrue(self.loop.is_running())

# Our custom "event loop" just iterates 10 times before exiting.
for i in range(10):
self.loop._run_once()

# Clean up the event loop
self.loop.run_forever_cleanup(orig_state)

# Confirm the loop has been cleaned up
with self.assertRaises(RuntimeError):
asyncio.get_running_loop()
self.assertFalse(self.loop.is_running())

# Confirm the loop actually did run, processing events 10 times,
# and invoking the callback once.
self.assertEqual(self.loop._process_events.call_count, 10)
self.assertEqual(count, 1)

async def leave_unfinalized_asyncgen(self):
# Create an async generator, iterate it partially, and leave it
# to be garbage collected.
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp