8000 gh-127049: Fix `asyncio.subprocess.Process` race condition killing an unrelated process on Unix by gschaffner · Pull Request #127051 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-127049: Fix asyncio.subprocess.Process race condition killing an unrelated process on Unix #127051

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Partially revert "gh-87744: fix waitpid race while calling send_signa…
…l in asyncio (#121126)"

This reverts the non-test changes of commit bd473aa.
  • Loading branch information
gschaffner committed Nov 19, 2024
commit a50f0b8f9d2dbece92a7ae1d3c2844b439785b09
35 changes: 9 additions & 26 deletions Lib/asyncio/base_subprocess.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import collections
import subprocess
import warnings
import os
import signal
import sys

from . import protocols
from . import transports
Expand Down Expand Up @@ -145,31 +142,17 @@ def _check_proc(self):
if self._proc is None:
raise ProcessLookupError()

if sys.platform == 'win32':
def send_signal(self, signal):
self._check_proc()
self._proc.send_signal(signal)

def terminate(self):
self._check_proc()
self._proc.terminate()

def kill(self):
self._check_proc()
self._proc.kill()
else:
def send_signal(self, signal):
self._check_proc()
try:
os.kill(self._proc.pid, signal)
except ProcessLookupError:
pass
def send_signal(self, signal):
self._check_proc()
self._proc.send_signal(signal)

def terminate(self):
self.send_signal(signal.SIGTERM)
def terminate(self):
self._check_proc()
self._proc.terminate()

def kill(self):
self.send_signal(signal.SIGKILL)
def kill(self):
self._check_proc()
self._proc.kill()

async def _connect_pipes(self, waiter):
try:
Expand Down
0