importasyncioimportsysimportunittestimportasyncioasyncio.set_child_watcher(asyncio.PidfdChildWatcher())
defcreate_free_port():
return4# chosen by a fair dice rollclassTestProc(unittest.IsolatedAsyncioTestCase):
asyncdefasyncSetUp(self):
self.port=create_free_port()
self.proc=awaitasyncio.create_subprocess_exec(
sys.executable,
"-c", # more realistically this might be an http server or databasef"import time; print('listening on {self.port}'); import time; time.sleep(2); print('goodbye')",
)
asyncdeftestProc(self):
print(f"connecting to {self.port}")
asyncdefasyncTearDown(self):
awaitself.proc.communicate() # hangs forever on 3.11if__name__=="__main__":
unittest.main()on python3.10 this produces:
connecting to 4
listening on 4
goodbye
.
----------------------------------------------------------------------
Ran 1 test in 2.022s
OK
on python3.11 it hangs forever in await self.proc.communicate()
Originally posted by @graingert in #95736 (comment)
on python3.10 this produces:
on python3.11 it hangs forever in
await self.proc.communicate()Originally posted by @graingert in #95736 (comment)