mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	[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 bd473aa598)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
			
			
This commit is contained in:
		
							parent
							
								
									af89237c9c
								
							
						
					
					
						commit
						d481d4b767
					
				
					 3 changed files with 42 additions and 9 deletions
				
			
		|  | @ -1,6 +1,9 @@ | |||
| import collections | ||||
| import subprocess | ||||
| import warnings | ||||
| import os | ||||
| import signal | ||||
| import sys | ||||
| 
 | ||||
| from . import protocols | ||||
| from . import transports | ||||
|  | @ -142,17 +145,31 @@ def _check_proc(self): | |||
|         if self._proc is None: | ||||
|             raise ProcessLookupError() | ||||
| 
 | ||||
|     def send_signal(self, signal): | ||||
|         self._check_proc() | ||||
|         self._proc.send_signal(signal) | ||||
|     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 terminate(self): | ||||
|             self._check_proc() | ||||
|             self._proc.terminate() | ||||
| 
 | ||||
|     def kill(self): | ||||
|         self._check_proc() | ||||
|         self._proc.kill() | ||||
|         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 terminate(self): | ||||
|             self.send_signal(signal.SIGTERM) | ||||
| 
 | ||||
|         def kill(self): | ||||
|             self.send_signal(signal.SIGKILL) | ||||
| 
 | ||||
|     async def _connect_pipes(self, waiter): | ||||
|         try: | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)