import asyncio async def test(): process = await asyncio.create_subprocess_shell( "sleep 2 && echo done", stdout=asyncio.subprocess.PIPE, ) await asyncio.sleep(1) process.kill() await process.wait() # process._transport.close() asyncio.run(test())