Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
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
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
a0c1fde67bfc8f3dcf97b35271dc6672f6854349c3e6226a523852d0e7f892ef94494431431261b3e3d8File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -601,29 +601,59 @@ def _check_running(self): | ||||||||
| raise RuntimeError( | ||||||||
| 'Cannot run the event loop while another loop is running') | ||||||||
| def run_forever_setup(self): | ||||||||
| """Set up an event loop so that it is ready to start actively looping | ||||||||
| to process events. | ||||||||
| ||||||||
| """Setupaneventloopsothatitisreadytostartactivelylooping | |
| toprocessevents. | |
| """Prepareforprocessingevents. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Document the type of the state, please. (If it's meant to be opaque, make it more opaque than a 1-tuple please. :-)
I find it a bit odd that the method name is "run_forever_setup()", which doesn't hint at the existence of a return value. (Could you store the state to be restored in a private/protected instance variable instead of returning it?)
Also, "arguments"? Or "argument"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I've modified the implementation to store the state as a protected variable, which simplifies the interface.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
"is only needed if" -- odd phrasing. The method exists. Do you mean it only needs to be overridden? Maybe show a brief example of how it's supposed to be used in that case? (I intentionally didn't the docs before reading the code, and from only reading the docstring I'm a bit confused about what's hooking what. From reading more code I realize that setup/cleanup are what you intend to override.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
No - it would be run_forever() that is being replaced. I've provided a sample implementation in the docs; I'll clarify the language here to (hopefully) make the intended usage more clear.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| """Cleanupaneventloopaftertheeventloopfinishestheloopingover | |
| events. | |
| """Cleanupaftertheeventloopfinishestheloopingoverevents. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Maybe clarify in this docstring that this is what calls setup/cleanup?
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -314,24 +314,25 @@ def __init__(self, proactor=None): | ||
| proactor = IocpProactor() | ||
| super().__init__(proactor) | ||
| def run_forever_setup(self): | ||
| assert self._self_reading_future is None | ||
| self.call_soon(self._loop_self_reading) | ||
gvanrossum marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| return super().run_forever_setup() | ||
| def run_forever_cleanup(self, orig_state): | ||
| ||
| if self._self_reading_future is not None: | ||
| ov = self._self_reading_future._ov | ||
| self._self_reading_future.cancel() | ||
| # self_reading_future was just cancelled so if it hasn't been | ||
| # finished yet, it never will be (it's possible that it has | ||
| # already finished and its callback is waiting in the queue, | ||
| # where it could still happen if the event loop is restarted). | ||
| # Unregister it otherwise IocpProactor.close will wait for it | ||
| # forever | ||
| if ov is not None: | ||
| self._proactor._unregister(ov) | ||
| self._self_reading_future = None | ||
| async def create_pipe_connection(self, protocol_factory, address): | ||
| f = self._proactor.connect_pipe(address) | ||