René's URL Explorer Experiment


Title: Nested multiprocessing leads to `AttributeError: is_fork_ctx` with `forkserver` or `spawn` methods · Issue #108520 · python/cpython · GitHub

Open Graph Title: Nested multiprocessing leads to `AttributeError: is_fork_ctx` with `forkserver` or `spawn` methods · Issue #108520 · python/cpython

X Title: Nested multiprocessing leads to `AttributeError: is_fork_ctx` with `forkserver` or `spawn` methods · Issue #108520 · python/cpython

Description: Bug report Checklist I am confident this is a bug in CPython, not a bug in a third-party project I have searched the CPython issue tracker, and am confident this bug has not been reported before CPython versions tested on: 3.11 Operating...

Open Graph Description: Bug report Checklist I am confident this is a bug in CPython, not a bug in a third-party project I have searched the CPython issue tracker, and am confident this bug has not been reported before CP...

X Description: Bug report Checklist I am confident this is a bug in CPython, not a bug in a third-party project I have searched the CPython issue tracker, and am confident this bug has not been reported before CP...

Opengraph URL: https://github.com/python/cpython/issues/108520

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Nested multiprocessing leads to `AttributeError: is_fork_ctx` with `forkserver` or `spawn` methods","articleBody":"# Bug report\n\n### Checklist\n\n- [X] I am confident this is a bug in CPython, not a bug in a third-party project\n- [X] I have searched the [CPython issue tracker](https://github.com/python/cpython/issues?q=is%3Aissue+sort%3Acreated-desc),\nand am confident this bug has not been reported before\n\n\n### CPython versions tested on:\n\n3.11\n\n### Operating systems tested on:\n\nLinux\n\n### Output from running 'python -VV' on the command line:\n\nPython 3.11.5 (main, Aug 26 2023, 00:26:34) [GCC 12.2.1 20220924]\n\n### A clear and concise description of the bug:\n\nUsing nested `multiprocessing` (i.e. spawn a child process inside a child process) is broken as of Python 3.11.5, leading to an attribute error.\n\n```python\nProcess Process-1:\nTraceback (most recent call last):\n  File \"/usr/local/lib/python3.11/multiprocessing/process.py\", line 314, in _bootstrap\n    self.run()\n  File \"/usr/local/lib/python3.11/multiprocessing/process.py\", line 108, in run\n    self._target(*self._args, **self._kwargs)\n  File \"/io/pyi_multiprocessing_nested_process.py\", line 15, in process_function\n    process.start()\n  File \"/usr/local/lib/python3.11/multiprocessing/process.py\", line 121, in start\n    self._popen = self._Popen(self)\n                  ^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/multiprocessing/context.py\", line 224, in _Popen\n    return _default_context.get_context().Process._Popen(process_obj)\n           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/multiprocessing/context.py\", line 288, in _Popen\n    return Popen(process_obj)\n           ^^^^^^^^^^^^^^^^^^\n  File \"/usr/local/lib/python3.11/multiprocessing/popen_spawn_posix.py\", line 32, in __init__\n    super().__init__(process_obj)\n  File \"/usr/local/lib/python3.11/multiprocessing/popen_fork.py\", line 19, in __init__\n    self._launch(process_obj)\n  File \"/usr/local/lib/python3.11/multiprocessing/popen_spawn_posix.py\", line 47, in _launch\n    reduction.dump(process_obj, fp)\n  File \"/usr/local/lib/python3.11/multiprocessing/reduction.py\", line 60, in dump\n    ForkingPickler(file, protocol).dump(obj)\n  File \"/usr/local/lib/python3.11/multiprocessing/synchronize.py\", line 106, in __getstate__\n    if self.is_fork_ctx:\n       ^^^^^^^^^^^^^^^^\nAttributeError: 'Lock' object has no attribute 'is_fork_ctx'\nResults: [1]\n```\n\nMinimal code example below. Invoke with argument `fork`, `forkserver` or `spawn`. `fork` will work. `forkserver` and `spawn` will both raise the above error. All three variants work with Python 3.11.4.\n\n```python\nimport sys\nimport multiprocessing\n\n\ndef nested_process_function(queue):\n    print(\"Running nested sub-process!\")\n    queue.put(2)\n\n\ndef process_function(queue):\n    print(\"Running sub-process!\")\n    queue.put(1)\n\n    process = multiprocessing.Process(target=nested_process_function, args=(queue,))\n    process.start()\n    process.join()\n\n\ndef main(start_method):\n    multiprocessing.set_start_method(start_method)\n    queue = multiprocessing.Queue()\n\n    process = multiprocessing.Process(target=process_function, args=(queue,))\n    process.start()\n    process.join()\n\n    results = []\n    while not queue.empty():\n        results.append(queue.get())\n\n    print(f\"Results: {results}\")\n    assert results == [1, 2]\n\n\nif __name__ == '__main__':\n    if len(sys.argv) != 2:\n        raise SystemExit(f\"Usage: {sys.argv[0]} fork|forkserver|spawn\")\n\n    main(sys.argv[1])\n```\n\nI believe that the source of this regression is https://github.com/python/cpython/commit/34ef75d3ef559288900fad008f05b29155eb8b59 which adds the attribute `is_fork_ctx` to `multiprocessing.Lock()` but doesn't update the pickle methods (`__getstate__()` and `__setstate__()`) so after being serialised and deserialised, the `Lock()` object looses that attribute.\n\nThe following patch, adding `is_fork_ctx` to the pickle methods, makes the above work again.\n```diff\ndiff --git a/Lib/multiprocessing/synchronize.py b/Lib/multiprocessing/synchronize.py\nindex 2328d33212..9c5c2aada6 100644\n--- a/Lib/multiprocessing/synchronize.py\n+++ b/Lib/multiprocessing/synchronize.py\n@@ -109,10 +109,11 @@ def __getstate__(self):\n                                    'not supported. Please use the same context to create '\n                                    'multiprocessing objects and Process.')\n             h = sl.handle\n-        return (h, sl.kind, sl.maxvalue, sl.name)\n+        return (h, sl.kind, sl.maxvalue, sl.name, self.is_fork_ctx)\n \n     def __setstate__(self, state):\n-        self._semlock = _multiprocessing.SemLock._rebuild(*state)\n+        self._semlock = _multiprocessing.SemLock._rebuild(*state[:4])\n+        self.is_fork_ctx = state[4]\n         util.debug('recreated blocker with handle %r' % state[0])\n         self._make_methods()\n```\n\n```[tasklist]\n### Tasks\n```\n\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-108568\n* gh-108691\n* gh-108692\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/bwoodsend","@type":"Person","name":"bwoodsend"},"datePublished":"2023-08-26T18:14:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":9},"url":"https://github.com/108520/cpython/issues/108520"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:54c41f18-92de-11b5-6531-7bd11b854f7a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id99CA:4D95E:852F03:BC2FC4:696A15B3
html-safe-noncecaf32b7689d1251b9d3a2cd515db21de1f2ad1ea6d54efb42d06f11315968d2a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OUNBOjREOTVFOjg1MkYwMzpCQzJGQzQ6Njk2QTE1QjMiLCJ2aXNpdG9yX2lkIjoiMTY1NzEyMTU4NTcwMjI0NTgxMSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac623f1783d5cb3d89c0ec84bb6b3dd8df67de65c1b3c8f5faf6979f026995aa19
hovercard-subject-tagissue:1868196368
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/108520/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b277208a927aeb13d89cab715c15fa98cecb343fa7aaa3dd81397d726fb68aa7/python/cpython/issues/108520
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b277208a927aeb13d89cab715c15fa98cecb343fa7aaa3dd81397d726fb68aa7/python/cpython/issues/108520
og:image:altBug report Checklist I am confident this is a bug in CPython, not a bug in a third-party project I have searched the CPython issue tracker, and am confident this bug has not been reported before CP...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebwoodsend
hostnamegithub.com
expected-hostnamegithub.com
None34a52bd10bd674f68e5c1b6b74413b79bf2ca20c551055ace3f7cdd112803923
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasee8bd37502700f365b18a4d39acf7cb7947e11b1a
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/108520#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F108520
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F108520
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/108520
Reloadhttps://github.com/python/cpython/issues/108520
Reloadhttps://github.com/python/cpython/issues/108520
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/108520
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/108520
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/108520
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/108520
Nested multiprocessing leads to AttributeError: is_fork_ctx with forkserver or spawn methodshttps://github.com/python/cpython/issues/108520#top
topic-multiprocessinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-multiprocessing%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com/bwoodsend
https://github.com/bwoodsend
bwoodsendhttps://github.com/bwoodsend
on Aug 26, 2023https://github.com/python/cpython/issues/108520#issue-1868196368
CPython issue trackerhttps://github.com/python/cpython/issues?q=is%3Aissue+sort%3Acreated-desc
34ef75dhttps://github.com/python/cpython/commit/34ef75d3ef559288900fad008f05b29155eb8b59
gh-108520: Fix bad fork detection in nested multiprocessing use case #108568https://github.com/python/cpython/pull/108568
[3.12] gh-108520: Fix bad fork detection in nested multiprocessing use case (GH-108568) #108691https://github.com/python/cpython/pull/108691
[3.11] gh-108520: Fix bad fork detection in nested multiprocessing use case (GH-108568) #108692https://github.com/python/cpython/pull/108692
topic-multiprocessinghttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22topic-multiprocessing%22
type-bugAn unexpected behavior, bug, or errorhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-bug%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.