Repository navigation
Pyjoyment, Pyjo.Promise: async actions and their requests are cancelled when the connection closes - #611
Merged
Conversation
…tines and of requests run_coroutine returns a function that cancels the coroutine where it waits, with CancelledError of the base class or asyncio.CancelledError of the task of Pyjo.Reactor.Asyncio, and cancels the promise that it waits for. A promise takes the function of its cancellation with cancel=, and cancel() calls it once, as nothing waits for the promise anymore, which then is not reported as an unhandled rejected promise; the one of a coroutine cancels it, and the one of start_p closes the connection of its request, also after a redirect, and is rejected with "Request cancelled". Part of #266 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts connection closes before its response ends Unlike Mojolicious, whose async sub runs to its end with the requests that it waits for: the coroutine gets the cancellation where it waits, its finally blocks run, and the request of the user agent that it waits for closes its connection, so that a request to a slow service, as a model of language, whose answer nobody reads anymore, stops too. An action that has rendered its response goes on, and the cancellation renders no exception page. Part of #266 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 tasks done
Contributor
Docker Smoke Test
|
Contributor
Tests
|
…has started, not after a time that a slow runner exceeds Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3 tasks done
… of cancel as the value of then, whose rejection the next promise would adopt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 tasks done
3 tasks done
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.
The first step of #266: an
async defaction whose connection closes before its response ends is cancelled, with the request of the user agent that it waits for. The next steps of #266 come as pull requests stacked on this one.Changes
Pyjo.Reactor.run_coroutinereturns a function that cancels the coroutine where it waits, and cancels the promise that it waits for;Nonefor a reactor that cannot.Pyjo.Reactor.Poll, gevent and Twisted run, throwsPyjo.Reactor.CancelledError, aBaseException, asexcept Exceptiondoes not catchasyncio.CancelledErroreither.Pyjo.Reactor.Asynciocancels the task, and itsawaitablecancels the promise when the wait of the task is cancelled; uvloop and Winloop inherit it.Pyjo.Promise:cancel=gives a promise the function of its cancellation, andcancel()calls it once, for a pending promise, which is then not reported as an unhandled rejected promise.Pyjo.UserAgent.start_p, and soget_pand the others:cancel()closes the connection of the request, also of the one after a redirect, found by its callback, and the promise is rejected withRequest cancelled.Pyjoyment: an action that is a coroutine function is cancelled when the transaction finishes before its response does, as when the client goes away or the inactivity timeout passes, with# Unlike Mojolicious:, whoseasync subruns to its end. The cancellation renders no exception page; an action that has rendered its response goes on to its end.asyncanddistributions.Reactors of the distributions
t/Pyjoyment/cancel_lite_app.pyand the tests of promises and of the user agent.run_coroutineof Pyjo-Reactor-Trio returnsNone, so the action runs to its end there, as before.cancel_lite_app.pyskips on a reactor that cannot cancel, so that the daily suite of Trio stays green, until Trio cancels its task with a cancel scope, in Pyjo.Reactor.Trio: run_coroutine returns a function that cancels the task Pyjo-Reactor-Trio#17, which tests against this branch.Validation
Pyjo.Reactor.PollwithPYTHONDEVMODE=1, without aResourceWarningor an unhandled rejected promiset/servers, Sphinx with-W,trunk checkt/Pyjoyment/cancel_lite_app.py: a client that gives up while the action waits for a request, a stream of Server-Sent Events whose client has gone, an action that goes on after its response, and a request cancelled after a redirectt/stdlib/Promise.pyon both reactors:finallyruns andexcept Exceptiondoes not catch it, the promise that the coroutine waits for and a coroutine in it are cancelled, a coroutine that goes on after it, and a cancellation before the first step without warningsPart of #266
🤖 Generated with Claude Code