Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e0d6de5

Browse filesBrowse files
fix send_signal race
1 parent ef3c400 commit e0d6de5
Copy full SHA for e0d6de5

File tree

2 files changed

+22
-5
lines changed
Filter options

2 files changed

+22
-5
lines changed

‎Lib/asyncio/base_subprocess.py

Copy file name to clipboardExpand all lines: Lib/asyncio/base_subprocess.py
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import collections
22
import subprocess
33
import warnings
4+
import os
5+
import signal
46

57
from . import protocols
68
from . import transports
@@ -144,15 +146,16 @@ def _check_proc(self):
144146

145147
def send_signal(self, signal):
146148
self._check_proc()
147-
self._proc.send_signal(signal)
149+
try:
150+
os.kill(self._proc.pid, signal)
151+
except ProcessLookupError:
152+
pass
148153

149154
def terminate(self):
150-
self._check_proc()
151-
self._proc.terminate()
155+
self.send_signal(signal.SIGTERM)
152156

153157
def kill(self):
154-
self._check_proc()
155-
self._proc.kill()
158+
self.send_signal(signal.SIGKILL)
156159

157160
async def _connect_pipes(self, waiter):
158161
try:

‎Lib/test/test_asyncio/test_subprocess.py

Copy file name to clipboardExpand all lines: Lib/test/test_asyncio/test_subprocess.py
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,20 @@ async def main():
864864

865865
self.loop.run_until_complete(main())
866866

867+
def test_subprocess_send_signal_race(self):
868+
# See https://github.com/python/cpython/issues/87744
869+
async def main():
870+
for _ in range(10):
871+
proc = await asyncio.create_subprocess_exec('sleep', '0.1')
872+
await asyncio.sleep(0.1)
873+
try:
874+
proc.send_signal(signal.SIGUSR1)
875+
except ProcessLookupError:
876+
pass
877+
self.assertNotEqual(await proc.wait(), 255)
878+
879+
self.loop.run_until_complete(main())
880+
867881

868882
if sys.platform != 'win32':
869883
# Unix

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.