Fix test_fork.py failures on Python 3.15 due to fork() DeprecationWarning in multi-threaded processes

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Python Drivers
    • Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      No driver behavior change; the fix is test-only. Add a note to the existing "PyMongo multiprocessing" / "multiple forks" docs (connect/mongoclient): Python 3.12+ raises a DeprecationWarning when os.fork() is called in a multi-threaded process. PyMongo's register_at_fork handlers reset its locks in the child, so the warning is benign when PyMongo's own threads are the only additional threads; users with other threads holding unmanaged locks should still address it.
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      No — there is no API or behavior change to demonstrate.
      3. Which versions of the driver/connector does this apply to?
      PyMongo 4.x running on Python 3.12+.

      Show
      1. What would you like to communicate to the user about this feature? No driver behavior change; the fix is test-only. Add a note to the existing "PyMongo multiprocessing" / "multiple forks" docs (connect/mongoclient): Python 3.12+ raises a DeprecationWarning when os.fork() is called in a multi-threaded process. PyMongo's register_at_fork handlers reset its locks in the child, so the warning is benign when PyMongo's own threads are the only additional threads; users with other threads holding unmanaged locks should still address it. 2. Would you like the user to see examples of the syntax and/or executable code and its output? No — there is no API or behavior change to demonstrate. 3. Which versions of the driver/connector does this apply to? PyMongo 4.x running on Python 3.12+.
    • None
    • None
    • None
    • None
    • None
    • None

      Summary

      Three tests in test/test_fork.py fail on Python 3.15 (ubuntu-latest) in GitHub Actions CI on PR #2840 (PYTHON-5837 Add beta Python 3.15).

      Failing Tests

      • test/test_fork.py::TestFork::test_lock_client
      • test/test_fork.py::TestFork::test_lock_object_id
      • test/test_fork.py::TestFork::test_topology_reset

      Error

      FAILED test/test_fork.py::TestFork::test_lock_client - DeprecationWarning: This process (pid=3104) is multi-threaded, use of fork() may lead to deadlocks in the child.
      FAILED test/test_fork.py::TestFork::test_lock_object_id - DeprecationWarning: This process (pid=3104) is multi-threaded, use of fork() may lead to deadlocks in the child.
      FAILED test/test_fork.py::TestFork::test_topology_reset - DeprecationWarning: This process (pid=3104) is multi-threaded, use of fork() may lead to deadlocks in the child.
      = 3 failed, 4633 passed, 3416 skipped ... in 715.16s =
      

      Context

      Python 3.12 introduced a DeprecationWarning when os.fork() is called in a multi-threaded process. On Python 3.15, this causes the fork tests to fail (likely because warnings are treated as errors in the test configuration, or the behavior changed further).

      Observed in: https://github.com/mongodb/mongo-python-driver/actions/runs/27243403891/job/80452029519

      Resolution

      The fork tests need to be updated to handle or suppress this warning on Python 3.15+, or the underlying forking approach needs to be revisited for multi-threaded contexts.

            Assignee:
            Steve Silvester
            Reporter:
            Alex Clark
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: