mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	bpo-38323: Add guard clauses in MultiLoopChildWatcher. (GH-22756)
This is a trivial refactor in preparation for a fix for bpo-38323.
(cherry picked from commit 66d3b589c4)
Co-authored-by: Chris Jerdonek <chris.jerdonek@gmail.com>
			
			
This commit is contained in:
		
							parent
							
								
									9d409d6b47
								
							
						
					
					
						commit
						bf0eed3e60
					
				
					 1 changed files with 19 additions and 15 deletions
				
			
		|  | @ -1230,13 +1230,15 @@ def is_active(self): | |||
| 
 | ||||
|     def close(self): | ||||
|         self._callbacks.clear() | ||||
|         if self._saved_sighandler is not None: | ||||
|             handler = signal.getsignal(signal.SIGCHLD) | ||||
|             if handler != self._sig_chld: | ||||
|                 logger.warning("SIGCHLD handler was changed by outside code") | ||||
|             else: | ||||
|                 signal.signal(signal.SIGCHLD, self._saved_sighandler) | ||||
|             self._saved_sighandler = None | ||||
|         if self._saved_sighandler is None: | ||||
|             return | ||||
| 
 | ||||
|         handler = signal.getsignal(signal.SIGCHLD) | ||||
|         if handler != self._sig_chld: | ||||
|             logger.warning("SIGCHLD handler was changed by outside code") | ||||
|         else: | ||||
|             signal.signal(signal.SIGCHLD, self._saved_sighandler) | ||||
|         self._saved_sighandler = None | ||||
| 
 | ||||
|     def __enter__(self): | ||||
|         return self | ||||
|  | @ -1263,15 +1265,17 @@ def attach_loop(self, loop): | |||
|         # The reason to do it here is that attach_loop() is called from | ||||
|         # unix policy only for the main thread. | ||||
|         # Main thread is required for subscription on SIGCHLD signal | ||||
|         if self._saved_sighandler is None: | ||||
|             self._saved_sighandler = signal.signal(signal.SIGCHLD, self._sig_chld) | ||||
|             if self._saved_sighandler is None: | ||||
|                 logger.warning("Previous SIGCHLD handler was set by non-Python code, " | ||||
|                                "restore to default handler on watcher close.") | ||||
|                 self._saved_sighandler = signal.SIG_DFL | ||||
|         if self._saved_sighandler is not None: | ||||
|             return | ||||
| 
 | ||||
|             # Set SA_RESTART to limit EINTR occurrences. | ||||
|             signal.siginterrupt(signal.SIGCHLD, False) | ||||
|         self._saved_sighandler = signal.signal(signal.SIGCHLD, self._sig_chld) | ||||
|         if self._saved_sighandler is None: | ||||
|             logger.warning("Previous SIGCHLD handler was set by non-Python code, " | ||||
|                            "restore to default handler on watcher close.") | ||||
|             self._saved_sighandler = signal.SIG_DFL | ||||
| 
 | ||||
|         # Set SA_RESTART to limit EINTR occurrences. | ||||
|         signal.siginterrupt(signal.SIGCHLD, False) | ||||
| 
 | ||||
|     def _do_waitpid_all(self): | ||||
|         for pid in list(self._callbacks): | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)