Title: Multiprocessing with "fork" fails with Python 3.14 but works with Python 3.13 · Issue #139894 · python/cpython · GitHub
Open Graph Title: Multiprocessing with "fork" fails with Python 3.14 but works with Python 3.13 · Issue #139894 · python/cpython
X Title: Multiprocessing with "fork" fails with Python 3.14 but works with Python 3.13 · Issue #139894 · python/cpython
Description: Bug report Bug description: The following code works fine on Python 3.13, but fails on Python 3.14 with a RuntimeError related to asyncio tasks. Minimal reproducible example import asyncio import inspect from functools import wraps from ...
Open Graph Description: Bug report Bug description: The following code works fine on Python 3.13, but fails on Python 3.14 with a RuntimeError related to asyncio tasks. Minimal reproducible example import asyncio import i...
X Description: Bug report Bug description: The following code works fine on Python 3.13, but fails on Python 3.14 with a RuntimeError related to asyncio tasks. Minimal reproducible example import asyncio import i...
Opengraph URL: https://github.com/python/cpython/issues/139894
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Multiprocessing with \"fork\" fails with Python 3.14 but works with Python 3.13","articleBody":"# Bug report\n\n### Bug description:\n\nThe following code works fine on **Python 3.13**, but fails on **Python 3.14** with a `RuntimeError` related to asyncio tasks.\n\n### Minimal reproducible example\n\n```python\nimport asyncio\nimport inspect\nfrom functools import wraps\nfrom typing import Any, Awaitable, Callable, Union\n\nimport pytest\nfrom multiprocess import Pipe, Process\nfrom multiprocess.connection import Connection\n\nimport multiprocess as mp\nmp.set_start_method(method=\"fork\", force=True) # \"spawn\" works fine\n\n\nclass SubprocessError:\n def __init__(self, ex: Exception) -> None:\n self.exception = ex\n\n\ndef in_subprocess[T](func: Callable[..., Union[T, Awaitable[T]]]) -> Callable[..., Awaitable[T]]:\n @wraps(func)\n async def wrapper(*args: Any, **kwargs: Any) -> T:\n return await calculate_in_subprocess(func, *args, **kwargs)\n\n return wrapper\n\n\nasync def calculate_in_subprocess[T](func: Callable[..., Union[T, Awaitable[T]]], *args: Any, **kwargs: Any) -> T:\n rx, tx = Pipe(duplex=False) # receiver & transmitter ; Pipe is one-way only\n process = Process(target=_inner, args=(tx, func, *args), kwargs=kwargs)\n process.start()\n\n event = asyncio.Event()\n loop = asyncio.get_event_loop()\n loop.add_reader(fd=rx.fileno(), callback=event.set)\n\n if not rx.poll(): # do not use process.is_alive() as condition here\n await event.wait()\n\n loop.remove_reader(fd=rx.fileno())\n event.clear()\n\n result = rx.recv()\n process.join() # this blocks synchronously! make sure that process is terminated before you call join()\n rx.close()\n tx.close()\n\n if isinstance(result, SubprocessError):\n raise result.exception\n\n return result\n\n\ndef _inner[T](tx: Connection, fun: Callable[..., Union[T, Awaitable[T]]], *a, **kw_args) -> None:\n event_loop = None\n if inspect.iscoroutinefunction(fun):\n event_loop = asyncio.new_event_loop()\n asyncio.set_event_loop(event_loop)\n\n try:\n if event_loop is not None:\n res = event_loop.run_until_complete(fun(*a, **kw_args))\n else:\n res = fun(*a, **kw_args)\n except Exception as ex:\n tx.send(SubprocessError(ex=ex))\n else:\n tx.send(res)\n\n\n@pytest.mark.asyncio\nasync def test_in_subprocess_simple_async():\n @in_subprocess\n async def f() -> int:\n return 42\n\n assert await f() == 42\n```\n\n---\n\n### Error message with Python 3.14\n\n```\n-------------------------------- live log call ---------------------------------\nERROR asyncio:base_events.py:1875 Exception in callback \u003c_asyncio.TaskStepMethWrapper object at 0x7e71ba729ff0>()\nhandle: \u003cHandle \u003c_asyncio.TaskStepMethWrapper object at 0x7e71ba729ff0>()>\nTraceback (most recent call last):\n File \"/usr/lib/python3.14/asyncio/events.py\", line 94, in _run\n self._context.run(self._callback, *self._args)\n ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\nRuntimeError: Cannot enter into task \u003cTask pending name='Task-2' coro=\u003ctest_in_subprocess_simple_async.\u003clocals>.f() running at foo.py:73> cb=[_run_until_complete_cb() at /usr/lib/python3.14/asyncio/base_events.py:181]> while another task \u003cTask pending name='Task-1' coro=\u003ctest_in_subprocess_simple_async() running at foo.py:77> cb=[_run_until_complete_cb() at /usr/lib/python3.14/asyncio/base_events.py:181]> is being executed.\n```\n\n---\n\n### Environment\n\nInstalled packages (note: `multiprocess` must be installed from GitHub):\n\n```\ncertifi==2025.10.5\ncharset-normalizer==3.4.3\ndill==0.4.0\ndocker==7.1.0\nidna==3.10\niniconfig==2.1.0\nmultiprocess @ git+https://github.com/uqfoundation/multiprocess.git@02ea4bd36cac5013d70847815c92e1a736ef4a05\npackaging==25.0\npluggy==1.6.0\nPygments==2.19.2\npytest==8.4.2\npytest-asyncio==1.2.0\npytest_docker_tools==3.1.9\nrequests==2.32.5\nurllib3==2.5.0\n```\n\n---\n\nAnd before you say, that the error is in the third-party lib `multiprocess` and I should use `multiprocessing` instead of `multiprocess`: The bug even occurs with `multiprocessing` (just replace the lib in the code example above). In Python 3.13 it will fail with a `PicklingError` (which is expected for this example) but in Python 3.14 the `RuntimeError: Cannot enter into task` will be thrown (see above). So this issue must be in Python 3.14.\n\n\n### CPython versions tested on:\n\n3.14\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-139897\n* gh-139913\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/LostInDarkMath","@type":"Person","name":"LostInDarkMath"},"datePublished":"2025-10-10T08:14:16Z","url":"https://github.com/python/cpython/issues/139894"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1f82c0bf-c600-5d2a-c45f-70aa34844a0d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 88D0:21BD98:37A1840:467A71A:6B0222E7 |
| html-safe-nonce | 7712ef3fb01ac443eb849a99a1241c49497cdb3515adb1636041f6a20ad0d060 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OEQwOjIxQkQ5ODozN0ExODQwOjQ2N0E3MUE6NkIwMjIyRTciLCJ2aXNpdG9yX2lkIjoiNjMwNjYwMTY5NzE1ODUwNTE5MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 22984fd46afaf9cbf686de278fccefa33651b7f097182d2df97ef7f0861c7455 |
| hovercard-subject-tag | issue:3501853151 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/139894/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cb9649d8bac9193bc06b091440e8dcf8e7ee24fb6c1a510292fc44d6f3bf01ba/python/cpython/issues/139894 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cb9649d8bac9193bc06b091440e8dcf8e7ee24fb6c1a510292fc44d6f3bf01ba/python/cpython/issues/139894 |
| og:image:alt | Bug report Bug description: The following code works fine on Python 3.13, but fails on Python 3.14 with a RuntimeError related to asyncio tasks. Minimal reproducible example import asyncio import i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | LostInDarkMath |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width