Open gpshead opened 6 months ago
I suppose that there was third-party code that directly used start_new_thread()
, allocate_lock()
and other API. If they are still used in important code, this module can be considered as a tool for experts rather than simply an implementation detail. We should look how they are used and what can be alternatives.
Rough results searching in the top 8k PyPI projects (2024-02-22):
import _thread\b|from _thread import
: Found 236 matching lines in 114 projects
thread.*\bstart_new_thread\b
: Found 168 matching lines in 33 projects
thread.*\ballocate_lock\b
: Found 134 matching lines in 34 projects
FWIW, there is precedent with the imp
module. We deprecated it in 3.4 and removed it from the docs in 3.12.
Wow, still a lot. Some of those uses are likely legacy easy py3 porting results. But otherwise they can be introspected to inform us of what people may need. Some of these things already have exact replacements via threading
.
Randomly picking some to look at from the "start_new_thread" list... the code in pydevd
is disturbing. Monkey patching, talking about hiding things from Python, etc. barf. Maybe they have reasons to given what it is, but for any of these regardless of prohect... how much is 2.7 legacy vs necessary?
I guess "documentation" is the closest we're going to get to "fixing" this in the short term.
Feature or enhancement
Proposal:
The https://docs.python.org/3/library/_thread.html module has a history, it used to be
thread
in Python 2 and earlier IIRC. But we want everyone to usethreading
and the_
prefix is intentional to suggest "do not use". Can we take this private and deprecate its direct use?_thread.start_new_thread()
for example is not an API used by the standard library. We could delete that code (which launches untracked unjoinable threads). Possibly more.investigation into what code in the world does still use it as why would be helpful.
Has this already been discussed elsewhere?
No response given
Links to previous discussion of this feature:
No response