mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
gh-87744: fix waitpid race while calling send_signal in asyncio (#121126)
asyncio earlier relied on subprocess module to send signals to the process, this has some drawbacks one being that subprocess module unnecessarily calls waitpid on child processes and hence it races with asyncio implementation which internally uses child watchers. To mitigate this, now asyncio sends signals directly to the process without going through the subprocess on non windows systems. On Windows it fallbacks to subprocess module handling but on windows there are no child watchers so this issue doesn't exists altogether.
This commit is contained in:
parent
1a84bdc237
commit
bd473aa598
3 changed files with 42 additions and 9 deletions
|
@ -864,6 +864,21 @@ class SubprocessMixin:
|
|||
|
||||
self.loop.run_until_complete(main())
|
||||
|
||||
@unittest.skipIf(sys.platform != 'linux', "Linux only")
|
||||
def test_subprocess_send_signal_race(self):
|
||||
# See https://github.com/python/cpython/issues/87744
|
||||
async def main():
|
||||
for _ in range(10):
|
||||
proc = await asyncio.create_subprocess_exec('sleep', '0.1')
|
||||
await asyncio.sleep(0.1)
|
||||
try:
|
||||
proc.send_signal(signal.SIGUSR1)
|
||||
except ProcessLookupError:
|
||||
pass
|
||||
self.assertNotEqual(await proc.wait(), 255)
|
||||
|
||||
self.loop.run_until_complete(main())
|
||||
|
||||
|
||||
if sys.platform != 'win32':
|
||||
# Unix
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue