Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ResourceWarning on implicitly closed event pipe sockets #1125

Merged
merged 3 commits into from
Jun 12, 2023

Conversation

minrk
Copy link
Member

@minrk minrk commented Jun 12, 2023

closes spyder-ide/spyder#21017

since there's no 'on thread close event', we need to garbage collect event pipes periodically. I don't love this, and the old code was a lot simpler and closed things always and only when needed, but it's not a great pattern to rely on __del__ to close things, which is why it raises a ResourceWarning.

There will only be something to do when a thread has:

  1. triggered an event via print or flush, and
  2. closed

so run quite rarely (e.g. 10 seconds)

To see the issue, run:

import warnings
warnings.simplefilter("error", ResourceWarning)
from concurrent.futures import ThreadPoolExecutor

with ThreadPoolExecutor() as pool:
    pool.submit(print, 5)

since there's no 'on thread close event', so we need to garbage collect event pipes periodically.

There will only be something to do when a thread has:

1. triggered an event via print or flush, and
2. closed

so run quite rarely (e.g. 10 seconds)
@blink1073 blink1073 changed the title avoid ResourceWarning on implicitly closed event pipe sockets Avoid ResourceWarning on implicitly closed event pipe sockets Jun 12, 2023
Copy link
Member

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

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

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invoking warnings.simplefilter in the console results in an exception
2 participants