Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix test
  • Loading branch information
kumaraditya303 committed Jul 19, 2026
commit d723a091096d22f77f3f4bfb998f8ab4724ff8bd
39 changes: 19 additions & 20 deletions Lib/test/test_asyncio/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,37 +412,36 @@ def test_wait_even_if_pipe_is_open(self):
# despite the returncode being known.

async def run():
# Just setup a pipe to pass to the grandchild for reading to ensure it dies.
# Inheritable is to allow it to be passed on windows
r, w = os.pipe()
os.set_inheritable(r, True)

code = textwrap.dedent(f"""\
# The grandchild inherits the child's stdin and stdout pipes and
# keeps both open after the child is killed. It writes "ready"
# so we know it has started, and exits once its stdin hits EOF.
code = textwrap.dedent("""\
import subprocess, sys
subprocess.run([sys.executable, "-c", "import sys;sys.stdin.read()"])
subprocess.run([sys.executable, "-c",
"import sys; sys.stdout.write('ready');"
" sys.stdout.flush(); sys.stdin.read()"])
""")

proc = await asyncio.create_subprocess_exec(
sys.executable, "-c", code,
# This will be inherited by granchild and should not prevent
# *this* process from firing .wait().
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stdin=r,
pass_fds=(r,) if sys.platform != "win32" else (),
close_fds=False if sys.platform == "win32" else True,
)
os.close(r)

try:
# Ensure we start waiting before the process is killed.
wait_proc = asyncio.create_task(proc.wait())
await asyncio.sleep(0)
# Wait until the grandchild holds the inherited pipes; this
# also lets the wait() task register its waiter.
await proc.stdout.readexactly(5)
proc.kill()
await asyncio.wait_for(wait_proc, timeout=support.SHORT_TIMEOUT)
returncode = await asyncio.wait_for(
wait_proc, timeout=support.SHORT_TIMEOUT)
if sys.platform == 'win32':
self.assertIsInstance(returncode, int)
else:
self.assertEqual(-signal.SIGKILL, returncode)
finally:
os.close(w) # Allows the grandchild to exit
if proc.stdout is not None:
await proc.stdout.read()
proc.stdin.close() # let the grandchild exit
await proc.stdout.read()

self.loop.run_until_complete(run())

Expand Down
Loading