[Bugfix] Fix DPM replies timeout task context - #92
Draft
beauremus wants to merge 2 commits into
Draft
Conversation
Collaborator
|
The solution is to wrap the future in a async task and then wrap that async task in another and then wait for the whole thing? Seems pretty heavy for waiting for the next item in a stream. Nevermind. Gemini says:
Nothing like severely breaking backwards compatibility. |
rneswold
reviewed
Aug 12, 2026
| timeout_task = asyncio.create_task( | ||
| asyncio.wait_for(reply_task, tmo)) | ||
| ii = await timeout_task | ||
| if ii is None: |
Collaborator
There was a problem hiding this comment.
Two layers of tasks still seems a bit much. Can it be written as:
while True:
timeout_task = asyncio.create_task(
asyncio.wait_for(self.__anext__(), tmo))
ii = await timeout_task
if ii is None:
# etc., etc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue 2: [Bugfix] Resolve
RuntimeError('Timeout should be used inside a task')inacsys.dpm.replies()on Python 3.11+Status: Implemented on branch
fix/dpm-replies-task-context; full pytest suite passes locally. Draft PR pending.Summary
Make
acsys.dpm.DPM.replies()usable when its async generator is driven through an event loop on Python 3.11 and later, without exposing theasyncio.wait_for()task-context runtime error.Reproduction and current evidence
tests/test_dpm_task_context.pyreproduces the problem in the RED phase by:DPMinstance with a stubbed__anext__.replies_gen = dpm.replies(tmo=1.0)..send(None)while marking a bare event loop as running, without wrapping the generator in an active task.RuntimeErrormatchingTimeout should be used inside a task.The GREEN regression test continues the manually driven generator after the fix and verifies that the first yielded object is a task and that the reply is returned successfully.
The relevant implementation is
DPM.replies()inacsys/dpm/__init__.py, where each reply is awaited throughasyncio.wait_for(self.__anext__(), tmo).Scope
DPM.replies()and the Python 3.11+asynciorequirement involved in the failure.tmoremains the maximum interval between replies and anasyncio.TimeoutErrorremains the expected timeout signal.Acceptance criteria
RuntimeError('Timeout should be used inside a task')on Python 3.11+.DPM.replies(tmo=...)from a normal task continues to yield replies as before.asyncio.TimeoutErrorwith the documented behavior.Verification
.send(None)reproducer failed before the implementation change withRuntimeError('Timeout should be used inside a task').python -m pytest -q tests/test_dpm_task_context.py -W error::RuntimeWarningpassed.python -m pytest -qpassed (1 passed).self.__anext__()and a task for theasyncio.wait_for()coroutine, keeping Python 3.11+ timeout context execution inside a task.Dependencies and risks
DPMinitialization; implementation should also be validated through the real public setup path where practical.Review focus
asyncioimplementation detail.Out of scope
set_many()(Issue 3).asyncio.get_event_loop()calls in the package.