Skip to content

Instantly share code, notes, and snippets.

@laixintao
Created November 26, 2021 13:21
Show Gist options
  • Save laixintao/77b751b0a59d87cfbadf387637db561d to your computer and use it in GitHub Desktop.
Save laixintao/77b751b0a59d87cfbadf387637db561d to your computer and use it in GitHub Desktop.
import asyncio
async def subshell():
print("start sleep...")
process = await asyncio.create_subprocess_shell(
"sleep 23",
)
print("sub process create, my id {}".format(process, process.pid))
await asyncio.sleep(23)
loop = asyncio.get_event_loop()
loop.run_until_complete(subshell())
@laixintao
Copy link
Author

Linux:

vagrant@vagrant:~$ python3 asy.py
start sleep...
sub process create: <Process 13275>, 13275
vagrant@vagrant:~$ pstree -lasp 13275
systemd,1
  └─sshd,2096
      └─sshd,13174
          └─sshd,13213
              └─bash,13214
                  └─python3,13274 asy.py
                      └─sh,13275 -c sleep 13
                          └─sleep,13277 13

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment