Skip to content

Commit e64d508

Browse files
committed
revert reraising exceptiongroup as a TrioInternalError, mention that it may raise exceptiongroup in docstring
1 parent 4b393ed commit e64d508

File tree

1 file changed

+31
-38
lines changed

1 file changed

+31
-38
lines changed

src/trio/_subprocess.py

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import trio
1313

1414
from ._abc import AsyncResource, ReceiveStream, SendStream
15-
from ._core import Cancelled, ClosedResourceError, TaskStatus, TrioInternalError
15+
from ._core import ClosedResourceError, TaskStatus
1616
from ._deprecate import deprecated
1717
from ._highlevel_generic import StapledStream
1818
from ._subprocess_platform import (
@@ -30,9 +30,6 @@
3030

3131
from typing_extensions import Self, TypeAlias
3232

33-
if sys.version_info < (3, 11):
34-
from exceptiongroup import BaseExceptionGroup
35-
3633

3734
# Sphinx cannot parse the stringified version
3835
if sys.version_info >= (3, 9):
@@ -690,6 +687,7 @@ async def my_deliver_cancel(process):
690687
and the process exits with a nonzero exit status
691688
OSError: if an error is encountered starting or communicating with
692689
the process
690+
ExceptionGroup: if exceptions occur in `deliver_cancel`, or when exceptions occur when communicating with the subprocess. If strict_exception_groups is set to false in the global context, then single exceptions will be collapsed.
693691
694692
.. note:: The child process runs in the same process group as the parent
695693
Trio process, so a Ctrl+C will be delivered simultaneously to both
@@ -767,41 +765,36 @@ async def read_output(
767765
# so any exceptions get directly seen by users.
768766
# options needs a complex TypedDict. The overload error only occurs on Unix.
769767
proc = await open_process(command, **options) # type: ignore[arg-type, call-overload, unused-ignore]
770-
try:
771-
async with trio.open_nursery() as nursery:
772-
try:
773-
if input is not None:
774-
assert proc.stdin is not None
775-
nursery.start_soon(feed_input, proc.stdin)
776-
proc.stdin = None
777-
proc.stdio = None
778-
if capture_stdout:
779-
assert proc.stdout is not None
780-
nursery.start_soon(read_output, proc.stdout, stdout_chunks)
781-
proc.stdout = None
782-
proc.stdio = None
783-
if capture_stderr:
784-
assert proc.stderr is not None
785-
nursery.start_soon(read_output, proc.stderr, stderr_chunks)
786-
proc.stderr = None
787-
task_status.started(proc)
768+
async with trio.open_nursery() as nursery:
769+
try:
770+
if input is not None:
771+
assert proc.stdin is not None
772+
nursery.start_soon(feed_input, proc.stdin)
773+
proc.stdin = None
774+
proc.stdio = None
775+
if capture_stdout:
776+
assert proc.stdout is not None
777+
nursery.start_soon(read_output, proc.stdout, stdout_chunks)
778+
proc.stdout = None
779+
proc.stdio = None
780+
if capture_stderr:
781+
assert proc.stderr is not None
782+
nursery.start_soon(read_output, proc.stderr, stderr_chunks)
783+
proc.stderr = None
784+
task_status.started(proc)
785+
await proc.wait()
786+
except BaseException:
787+
with trio.CancelScope(shield=True):
788+
killer_cscope = trio.CancelScope(shield=True)
789+
790+
async def killer() -> None:
791+
with killer_cscope:
792+
await deliver_cancel(proc)
793+
794+
nursery.start_soon(killer)
788795
await proc.wait()
789-
except BaseException:
790-
with trio.CancelScope(shield=True):
791-
killer_cscope = trio.CancelScope(shield=True)
792-
793-
async def killer() -> None:
794-
with killer_cscope:
795-
await deliver_cancel(proc)
796-
797-
nursery.start_soon(killer)
798-
await proc.wait()
799-
killer_cscope.cancel()
800-
raise
801-
except BaseExceptionGroup as exc:
802-
if all(isinstance(e, Cancelled) for e in exc.exceptions):
803-
raise exc
804-
raise TrioInternalError("Error interacting with opened process") from exc
796+
killer_cscope.cancel()
797+
raise
805798

806799
stdout = b"".join(stdout_chunks) if capture_stdout else None
807800
stderr = b"".join(stderr_chunks) if capture_stderr else None

0 commit comments

Comments
 (0)