Skip to content

Instantly share code, notes, and snippets.

@laixintao
Created November 26, 2021 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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

Mac:

tmp ➜ python3 asy.py
start sleep...
sub process create, my id <Process 39656>
tmp ➜ pstree -p 39656
-+= 00001 root /sbin/launchd
 \-+= 01751 xintao.lai tmux
   \-+= 38831 xintao.lai -zsh
     \-+= 39640 xintao.lai /Users/xintao.lai/.pyenv/versions/3.8.5/bin/python3 asy.py
       \--- 39656 xintao.lai sleep 23
tmp ➜ ps -ef | grep 39640
1556639569 39640 38831   0  9:22PM ttys052    0:00.08 /Users/xintao.lai/.pyenv/versions/3.8.5/bin/python3 asy.py
1556639569 39656 39640   0  9:22PM ttys052    0:00.01 sleep 23
1556639569 39704 39657   0  9:22PM ttys056    0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn --exclude-dir=.idea --exclude-dir=.tox 39640

@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