mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	asyncio: __del__() keep reference to warnings.warn (GH-11491)
* asyncio: __del__() keep reference to warnings.warn The __del__() methods of asyncio classes now keep a strong reference to the warnings.warn() to be able to display the ResourceWarning warning in more cases. Ensure that the function remains available if instances are destroyed late during Python shutdown (while module symbols are cleared). * Rename warn parameter to _warn "_warn" name is a hint that it's not the regular warnings.warn() function.
This commit is contained in:
		
							parent
							
								
									9b07681c09
								
							
						
					
					
						commit
						fb2c3465f0
					
				
					 7 changed files with 16 additions and 24 deletions
				
			
		|  | @ -658,10 +658,9 @@ def close(self): | |||
|             self._loop._remove_writer(self._sock_fd) | ||||
|             self._loop.call_soon(self._call_connection_lost, None) | ||||
| 
 | ||||
|     def __del__(self): | ||||
|     def __del__(self, _warn=warnings.warn): | ||||
|         if self._sock is not None: | ||||
|             warnings.warn(f"unclosed transport {self!r}", ResourceWarning, | ||||
|                           source=self) | ||||
|             _warn(f"unclosed transport {self!r}", ResourceWarning, source=self) | ||||
|             self._sock.close() | ||||
| 
 | ||||
|     def _fatal_error(self, exc, message='Fatal error on transport'): | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner