Skip to content

Commit

Permalink
make ACK win32 specific
Browse files Browse the repository at this point in the history
easier than bugfixing py3.11/macos
  • Loading branch information
richardsheridan committed Jan 9, 2024
1 parent 1aa697e commit 574b719
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions _trio_parallel_workers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def worker_behavior(recv_pipe, send_pipe, idle_timeout, init, retire):
# between processes. (Trio will take charge via cancellation.)
signal.signal(signal.SIGINT, signal.SIG_IGN)
try:
if isinstance(init, bytes): # true except on "fork"
# Signal successful startup to spawn/forkserver parents.
if sys.platform == "win32":
# Signal successful startup.
send_pipe.send_bytes(ACK)
if isinstance(init, bytes): # true except on "fork"
init = loads(init)
if isinstance(retire, bytes): # true except on "fork"
retire = loads(retire)
init()
while safe_poll(recv_pipe, idle_timeout):
Expand Down
5 changes: 4 additions & 1 deletion trio_parallel/_proc.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ async def start(self):
self._child_send_pipe.close()
self._child_recv_pipe.close()

# The following is mainly needed in the case of accidental recursive spawn
if sys.platform != "win32":
return

# Give a nice error on accidental recursive spawn instead of hanging
async def wait_for_ack():
try:
code = await self._receive_chan.receive()
Expand Down
2 changes: 2 additions & 0 deletions trio_parallel/_tests/test_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ def test_startup_failure_doesnt_hang(tmp_path):
)
assert not result.stdout
assert b"An attempt has been made to start a new process" in result.stderr
assert b"ExceptionGroup" not in result.stderr
assert b"MultiError" not in result.stderr
assert result.returncode


Expand Down

0 comments on commit 574b719

Please sign in to comment.