Skip to content

Conversation

@iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Nov 7, 2020

enumerate() returns a list of all active thread objects, which contains all threads for which is_alive is true but may also contain threads (like the main thread) for which is_alive is False.

https://bugs.python.org/issue25821

The list returned by enumerate contains all alive threads, but may contain others.
@pitrou
Copy link
Member

pitrou commented Nov 7, 2020

"active" is undefined. I would rather keep the corrent wording, but perhaps add that the main thread is always there even when finished.

@iritkatriel
Copy link
Member Author

I picked up active from

.. function:: active_count()

   Return the number of :class:`Thread` objects currently alive.  The returned
   count is equal to the length of the list returned by :func:`.enumerate`.

@pitrou
Copy link
Member

pitrou commented Nov 7, 2020

Hmm, well you see that "active" is a synonym of "alive" in that instance.

@iritkatriel
Copy link
Member Author

iritkatriel commented Nov 7, 2020

There seems to be some distinction between "the thread object is alive" and thread.is_alive()

@pitrou
Copy link
Member

pitrou commented Nov 7, 2020

Perhaps the following will be clear (but more wordy):

   Return a list of all :class:`Thread` objects currently active.  The list
   includes daemonic threads, dummy thread objects created by
   :func:`current_thread`, and the main thread.  It excludes terminated threads
   and threads that have not yet been started. However, the main thread
   is always part of the result, even when terminated.

Copy link
Contributor

@taleinat taleinat left a comment

Choose a reason for hiding this comment

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

LGTM.

I think the change in threading.py is unnecessary, but harmless. @iritkatriel, let me know what you think about it, and then we can merge this.

Lib/threading.py Outdated
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
returns a list that contains all alive threads.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the existing wording is fine here; not sure why this change is need?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's because it may also contain a terminated main thread.

Copy link
Contributor

@taleinat taleinat Dec 23, 2020

Choose a reason for hiding this comment

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

That makes the new wording correct, but possibly misleading.

The sentence about enumerate() seems somewhat out of place here; perhaps it could just be removed? Otherwise let's add something like "(and always the main thread)" at the end.

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps just "see also .."?

Lib/threading.py Outdated
This method returns True just before the run() method starts until just
after the run() method terminates. The module function enumerate()
returns a list of all alive threads.
returns a list that contains all alive threads.
Copy link
Contributor

@taleinat taleinat Dec 23, 2020

Choose a reason for hiding this comment

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

That makes the new wording correct, but possibly misleading.

The sentence about enumerate() seems somewhat out of place here; perhaps it could just be removed? Otherwise let's add something like "(and always the main thread)" at the end.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@iritkatriel
Copy link
Member Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@taleinat: please review the changes made to this pull request.

@github-actions
Copy link

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale Stale PR or inactive for long period of time. label Jan 25, 2021
@taleinat
Copy link
Contributor

@iritkatriel, this is definitely ready to be merged. Now that you're a core dev, I'll leave it to you :)

@iritkatriel
Copy link
Member Author

Oh!

@iritkatriel iritkatriel merged commit 12e7d10 into python:main May 11, 2021
@bedevere-bot
Copy link

@iritkatriel: Please replace # with GH- in the commit message next time. Thanks!

@miss-islington
Copy link
Contributor

Thanks @iritkatriel for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.9.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 11, 2021
@bedevere-bot
Copy link

GH-26035 is a backport of this pull request to the 3.10 branch.

@bedevere-bot
Copy link

GH-26036 is a backport of this pull request to the 3.9 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 11, 2021
iritkatriel added a commit that referenced this pull request May 11, 2021
iritkatriel added a commit that referenced this pull request May 11, 2021
@iritkatriel iritkatriel deleted the bpo-25821 branch May 11, 2021 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants