diff options
| author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-07-01 05:11:47 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-01 05:11:47 (GMT) |
| commit | d481d4b7676f2e5d33465ca691346f69af655b24 (patch) | |
| tree | f1803cc7ea7152dc8af1ef30728f30fdedb66966 /Lib/test/test_asyncio/test_subprocess.py | |
| parent | af89237c9c1bdcda7915ea195b279734f7ebddf2 (diff) | |
| download | cpython-d481d4b7676f2e5d33465ca691346f69af655b24.zip cpython-d481d4b7676f2e5d33465ca691346f69af655b24.tar.gz cpython-d481d4b7676f2e5d33465ca691346f69af655b24.tar.bz2 | |
[3.13] gh-87744: fix waitpid race while calling send_signal in asyncio (GH-121126) (#121194)
gh-87744: fix waitpid race while calling send_signal in asyncio (GH-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.
(cherry picked from commit bd473aa598c5161521a7018896dc124728214a6c)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Diffstat (limited to 'Lib/test/test_asyncio/test_subprocess.py')
| -rw-r--r-- | Lib/test/test_asyncio/test_subprocess.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py index cf1a198..c822d80 100644 --- a/Lib/test/test_asyncio/test_subprocess.py +++ b/Lib/test/test_asyncio/test_subprocess.py @@ -873,6 +873,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 |
