mirror of
https://github.com/python/cpython.git
synced 2025-10-21 14:12:27 +00:00
gh-100228: Warn from os.fork() if other threads exist. (#100229)
Not comprehensive, best effort warning. There are cases when threads exist on some platforms that this code cannot detect. macOS when API permissions allow and Linux with a readable /proc procfs present are the currently supported cases where a warning should show up reliably. Starting with a DeprecationWarning for now, it is less disruptive than something like RuntimeWarning and most likely to only be seen in people's CI tests - a good place to start with this messaging.
This commit is contained in:
parent
2df82db485
commit
894f2c3c16
12 changed files with 283 additions and 66 deletions
|
@ -5,6 +5,7 @@ from test import support
|
|||
from test.support import threading_helper
|
||||
import _thread as thread
|
||||
import time
|
||||
import warnings
|
||||
import weakref
|
||||
|
||||
from test import lock_tests
|
||||
|
@ -238,11 +239,13 @@ class TestForkInThread(unittest.TestCase):
|
|||
def fork_thread(read_fd, write_fd):
|
||||
nonlocal pid
|
||||
|
||||
# fork in a thread
|
||||
pid = os.fork()
|
||||
if pid:
|
||||
# parent process
|
||||
return
|
||||
# Ignore the warning about fork with threads.
|
||||
with warnings.catch_warnings(category=DeprecationWarning,
|
||||
action="ignore"):
|
||||
# fork in a thread (DANGER, undefined per POSIX)
|
||||
if (pid := os.fork()):
|
||||
# parent process
|
||||
return
|
||||
|
||||
# child process
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue