GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||
GeezerVison is showing github.com — gh-110205: Fix asyncio ThreadedChildWatcher._join_threads() by vstinner · Pull Request #110790 · python/cpython Conversation
|
| self.threads = [thread for thread in list(self._threads.values()) | ||
| if thread.is_alive() and not thread.daemon] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Why are you creating a new instance variable self.threads here? Did you intend to clean out completed threads from the dict self._threads?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I used the list comprehension above as an example, for me it looks easier to remove completed threads rather than having a regular list and removing items from the list.
The purpose of this line is to remove completed threads to save memory and to fix the dangling threads issue.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that you prefer to not create a new list?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I modified my PR to use self.threads[:] = ..., so the self.threads list object is not replacd.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Do you mean that you prefer to not create a new list?
No I meant that the tests fail because self._threads is a dict, not a list.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
It fix the issue related to the PR: dangling thread. The warning can be emitted when the Python object still exist, even if the thread is no longer running. I don't think that copy/paste the _join_threads() logic in the test is worth it. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Please take a break and read the comments and the code. There is no variable |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Ah, I misunderstood your comment. I fixed the typo, the code now sets |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| self._threads[:] = [thread for thread in list(self._threads.values()) | ||
| if thread.is_alive() and not thread.daemon] |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As I was trying to let you see for yourself, self._threads is a dict, not a list. If you want to update it using a comprehension you can use something like this:
self._threads = {key: thread for key, thread in self._threads.items() if thread.daemon or thread.is_alive()}
Please test locally before merging.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.