This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: forkserver could warn if several threads are running
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: davin, giampaolo.rodola, gregory.p.smith, pitrou
Priority: low Keywords:

Created on 2017-10-31 18:12 by pitrou, last changed 2022-04-11 14:58 by admin.

Messages (3)
msg305323 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-10-31 18:12
I'm not sure this is worth handling, but I had an interaction with a user who had weird deadlock problems in a glibc function (getaddrinfo) in worker processes launched with the forkserver method.

The explanation turned out to be that a sitecustomize.py did some stuff that eventually launched a helper thread, and that made the forkserver process's forking fundamentally unsafe (fork() is guaranteed to be safe if there's only one thread running in the parent process).

It would be easy to check that threading.enumerate() returns only one thread, and otherwise warn the user about it.  Note this only handles Python threads and not C threads invisible to Python... (a more complete solution would involve psutil :-)).
msg305400 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2017-11-01 23:19
If we do this, I think we should aim for the complete solution on the most common posix platforms (Linux and MacOS) as C/C++ extensions are just as happy to create threads these days.  (but if you want to start with a simple python threads only warning, i'm not going to stop you)
msg305401 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2017-11-01 23:22
Yeah... We might replicate the psutil source code doing that.  On Linux, it involves parsing /proc/{pid}/status (which may not be available on some restricted execution environments?).  Haven't looked what it does on macOS.
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 76094
2017-11-01 23:22:22pitrousetnosy: + giampaolo.rodola
messages: + msg305401
2017-11-01 23:19:54gregory.p.smithsetmessages: + msg305400
2017-10-31 18:12:26pitroucreate