FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-26133: Dont unsubscribe signals in UNIX even loop on interpreter shutdown by asvetlov · Pull Request #4956 · python/cpython · GitHub

Repository navigation

bpo-26133: Dont unsubscribe signals in UNIX even loop on interpreter shutdown - #4956

Merged
asvetlov merged 5 commits into
python:masterfrom
asvetlov:bpo-26133
Dec 21, 2017
Merged

asvetlov merged 5 commits into
python:masterfrom
asvetlov:bpo-26133

Conversation

asvetlov commented Dec 21, 2017 •
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Contributor

Comment thread Lib/asyncio/unix_events.py Outdated
self.remove_signal_handler(sig)
else:
warinigs.warn(f"Closing the loop {self} on interpreter shutdown "
f"stage, signal unsubsription is disabled")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

stacklevel arg?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Sure! :)

Comment thread Lib/asyncio/unix_events.py Outdated
else:
warinigs.warn(f"Closing the loop {self} on interpreter shutdown "
f"stage, signal unsubsription is disabled",
stacklevel=2)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I'm not sure that stacklevel=2 is correct. Maybe remove it?

For the warning category, I hesitate to use ResourceWarning and pass source=self. ResourceWarning are quiet by default. It's maybe better to not pollute stdout with such warning?

Comment thread Lib/asyncio/unix_events.py Outdated
for sig in list(self._signal_handlers):
self.remove_signal_handler(sig)
else:
warinigs.warn(f"Closing the loop {self} on interpreter shutdown "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Please replace {self} with {self!r}. See for example BaseEventLoop.close() resource warning.

@@ -0,0 +1 @@
Dont unsubscribe signals in asyncio UNIX event loop on interpreter shutdown.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It should be written "Don't", no?

Copy link
Copy Markdown
Contributor Author

Notes are fixed.
Not sure about stacklevel too. With level 2 traceback points on __del__ most likely, with default it shows .close() explicitly.

Comment thread Lib/asyncio/unix_events.py Outdated
else:
warinigs.warn(f"Closing the loop {self!r} on interpreter shutdown "
f"stage, signal unsubsription is disabled",
ResourceWarning)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

For ResourceWarning, you can add source=self, so the warning will be logged with the traceback were the event loop was created, if traceback is enabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done

vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM.

It's hackish, but as I explained at https://bugs.python.org/issue26133#msg258429 it's hard to fix the root issue.

The hack is only used when the code doesn't explicitly close the event loop, which is a bug on itself. So it's ok to workaround https://bugs.python.org/issue26133 side effect.

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Copy link
Copy Markdown
Contributor

Thanks @asvetlov for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

Copy link
Copy Markdown

GH-4962 is a backport of this pull request to the 3.6 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 21, 2017
super().close()
for sig in list(self._signal_handlers):
self.remove_signal_handler(sig)
if not sys.is_finalizing():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

What happens if someone calls loop.close() twice? I guess self._signal_handlers.clear() is needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Double warning will be shown obviously.
But it is very rare situation: most likely the loop will be closed by __del__.
Even atexit callbacks are called when sys.is_finalizing() is False.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Well, in this case I'd like to clear the list of signal handlers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ok, will make a postfix PR soon.

1st1 commented Dec 21, 2017

Copy link
Copy Markdown
Member

Not sure about stacklevel too. With level 2 traceback points on del most likely, with default it shows .close() explicitly.

And what's the point of showing 'close()' explicitly? __del__ gives you an idea that the warning is triggered by the GC.

1st1 commented Dec 21, 2017

Copy link
Copy Markdown
Member

I'd appreciate if patches like this are merged with my approval.

Copy link
Copy Markdown
Contributor Author

@1st1 sorry

1st1 commented Dec 21, 2017 •
edited
Loading

Copy link
Copy Markdown
Member

NP, Andrew, it's not a big deal. I trust you and Victor completely. It's just that I have a few follow-up questions that I wish we discussed before the merge just in case.

asvetlov pushed a commit that referenced this pull request Dec 21, 2017

Copy link
Copy Markdown
Contributor Author

And what's the point of showing 'close()' explicitly? __del__ gives you an idea that the warning is triggered by the GC.

Stack trace points in __del__ too.
Any loop.close() at interpreter finalizing stage is dangerous and should be fixed. Well, not dangerous but very non-accurate, I'd like to discourage this antipattern.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL