GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||
GeezerVison is showing github.com — Serialize process spawning across threads with a lock by veeceey · Pull Request #728 · MagicStack/uvloop ConversationWhen multiple threads each run their own event loop and try to spawn processes concurrently, they race on the global This replaces the error-raising approach with a The lock is properly released in all error paths through a Repro from the issue now works without errors: import asyncio from threading import Thread import uvloop def create_processes(i): async def inner(): processes = [] for _ in range(100): p = await asyncio.create_subprocess_exec("true") processes.append(p) for p in processes: await p.wait() try: asyncio.run(inner()) print(f"[{i}] Success.") except Exception as e: print(f"[{i}] Fail: {repr(e)}") uvloop.install() threads = [Thread(target=lambda: create_processes(i)) for i in range(10)] for t in threads: t.start() for t in threads: t.join() # All threads now succeed instead of some failing with RuntimeError Fixes #508
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactionsReplace the RuntimeError-raising check for concurrent process spawning with a threading.Lock that serializes spawns across different event loops running in separate threads. The old approach would fail with "Racing with another loop to spawn a process" when multiple threads tried to spawn processes concurrently, since the global pthread_atfork handlers can only be active for one loop at a time. Now instead of failing, concurrent spawns wait for the lock, allowing them to proceed sequentially. The lock is properly released in all error paths via a finally block. Fixes MagicStack#508
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. setuptools>=78 removed the bundled pkg_resources module, causing ModuleNotFoundError on all CI jobs except Python 3.8-ubuntu (which uses an older setuptools). Use packaging.requirements.Requirement instead, which provides the same version-specifier matching and is always available as a dependency of setuptools.
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Author
All reactions
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabels
None yet
ProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. "RuntimeError: Racing with another loop to spawn a process" when spawning many processes from multiple threadsUh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. | |||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |