Skip to content

Commit

Permalink
pythongh-105288: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
keuin committed Jun 7, 2023
1 parent a54ad6f commit de7a41f
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Lib/test/test_asyncio/test_subprocess.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import signal
import sys
import threading
import time
import unittest
import warnings
from unittest import mock
Expand Down Expand Up @@ -787,6 +789,35 @@ async def main() -> None:

self.loop.run_until_complete(main())

def test_subprocess_wait_not_hang_gh105288(self):
# See https://github.com/python/cpython/issues/105288
TIMEOUT = 5
finished = False

async def whoami():
proc = await subprocess.create_subprocess_exec('whoami')
await proc.communicate()

async def main():
t = asyncio.create_task(whoami())
await asyncio.wait([0, t])

def _main():
nonlocal finished
try:
# We have to run the event loop in a separate thread,
# to make sure we can fail in the main thread
# and successfully notify the test driver.
self.loop.run_until_complete(main())
finally:
finished = True


threading.Thread(target=_main).start()
time.sleep(TIMEOUT)
if not finished:
self.fail('watchdog timeout, event loop is probably sleeping infinitely')

def test_subprocess_communicate_stdout(self):
# See https://github.com/python/cpython/issues/100133
async def get_command_stdout(cmd, *args):
Expand Down

0 comments on commit de7a41f

Please sign in to comment.