Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,17 @@ def _target() -> None:

ctx = multiprocessing.get_context("fork")
proc = ctx.Process(target=_target)
proc.start()
# Python 3.12+ warns when os.fork() runs in a multi-threaded process. The
# warning is a general thread-count heuristic; benign here because the only
# extra threads are pymongo's, whose locks are reset via register_at_fork
# in the child. Suppressed only in this helper, not globally (PYTHON-5874).
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
message=r".*use of fork\(\) may lead to deadlocks.*",
category=DeprecationWarning,
)
proc.start()
try:
yield proc # type: ignore
finally:
Expand Down
12 changes: 11 additions & 1 deletion test/asynchronous/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,17 @@ def _target() -> None:

ctx = multiprocessing.get_context("fork")
proc = ctx.Process(target=_target)
proc.start()
# Python 3.12+ warns when os.fork() runs in a multi-threaded process. The
# warning is a general thread-count heuristic; benign here because the only
# extra threads are pymongo's, whose locks are reset via register_at_fork
# in the child. Suppressed only in this helper, not globally (PYTHON-5874).
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore",
message=r".*use of fork\(\) may lead to deadlocks.*",
category=DeprecationWarning,
)
proc.start()
try:
yield proc # type: ignore
finally:
Expand Down
6 changes: 2 additions & 4 deletions test/test_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,15 @@
from test.utils_shared import is_greenthread_patched


# self.fork suppresses the Python 3.12+ fork() DeprecationWarning; it is
# benign for these intentional forks (PYTHON-5874).
@unittest.skipIf(
not hasattr(os, "register_at_fork"), "register_at_fork not available in this version of Python"
)
@unittest.skipIf(
is_greenthread_patched(),
"gevent does not support POSIX-style forking.",
)
@unittest.skipIf(
sys.version_info >= (3, 15),
"fork() in multi-threaded processes is deprecated in Python 3.15+ (PYTHON-5874)",
)
class TestFork(IntegrationTest):
def test_lock_client(self):
# Forks the client with some items locked.
Expand Down
Loading