Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncio.create_subprocess() cancellation #118516

Open
socketpair opened this issue May 2, 2024 · 1 comment
Open

asyncio.create_subprocess() cancellation #118516

socketpair opened this issue May 2, 2024 · 1 comment
Labels
docs Documentation in the Doc dir

Comments

@socketpair
Copy link
Contributor

socketpair commented May 2, 2024

Documentation

It's not documented, that .cancel() kills background process with kill(). At least on Linux:

from asyncio import Task, create_subprocess_exec, run, sleep
async def main():
    t = Task(create_subprocess_exec('sleep', '100'))
    await sleep(1)
    t.cancel()
    await t
run(main())
strace -t -ff -e clone,fork,vfork,execve,kill,wait4 /usr/bin/python3 test.py 
22:19:20 execve("/usr/bin/python3", ["/usr/bin/python3"], 0x7ffe4ff89598 /* 50 vars */) = 0
22:19:20 vfork(strace: Process 479095 attached
 <unfinished ...>
[pid 479095] 22:19:20 execve("/usr/bin/sleep", ["sleep", "100"], 0x7ffde73e6110 /* 50 vars */ <unfinished ...>
[pid 479094] 22:19:20 <... vfork resumed>) = 479095
[pid 479095] 22:19:20 <... execve resumed>) = 0
[pid 479094] 22:19:21 wait4(479095, 0x7ffde73e58d4, WNOHANG, NULL) = 0
[pid 479094] 22:19:21 wait4(479095, 0x7ffde73e5954, WNOHANG, NULL) = 0
[pid 479094] 22:19:21 kill(479095, SIGKILL) = 0
[pid 479094] 22:19:21 wait4(479095,  <unfinished ...>
[pid 479095] 22:19:21 +++ killed by SIGKILL +++
22:19:21 <... wait4 resumed>[{WIFSIGNALED(s) && WTERMSIG(s) == SIGKILL}], WNOHANG, NULL) = 479095
22:19:21 --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_KILLED, si_pid=479095, si_uid=1000, si_status=SIGKILL, si_utime=0, si_stime=0} ---
22:19:21 +++ exited with 0 +++
@socketpair socketpair added the docs Documentation in the Doc dir label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

1 participant