Skip to content

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)

@minrk minrk added the bug label Jun 12, 2023
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
Contributor

@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