mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	[3.13] gh-118727: Don't drop the GIL in drop_gil() unless the current thread holds it (GH-118745) (#119474)
				
					
				
			`drop_gil()` assumes that its caller is attached, which means that the current
thread holds the GIL if and only if the GIL is enabled, and the enabled-state
of the GIL won't change. This isn't true, though, because `detach_thread()`
calls `_PyEval_ReleaseLock()` after detaching and
`_PyThreadState_DeleteCurrent()` calls it after removing the current thread
from consideration for stop-the-world requests (effectively detaching it).
Fix this by remembering whether or not a thread acquired the GIL when it last
attached, in `PyThreadState._status.holds_gil`, and check this in `drop_gil()`
instead of `gil->enabled`.
This fixes a crash in `test_multiprocessing_pool_circular_import()`, so I've
reenabled it.
(cherry picked from commit be1dfccdf2)
Co-authored-by: Brett Simmers <swtaarrs@users.noreply.github.com>
			
			
This commit is contained in:
		
							parent
							
								
									8fd8cc564b
								
							
						
					
					
						commit
						d98d6b1776
					
				
					 5 changed files with 73 additions and 60 deletions
				
			
		|  | @ -17,7 +17,7 @@ | |||
| from test.support import verbose | ||||
| from test.support.import_helper import forget, mock_register_at_fork | ||||
| from test.support.os_helper import (TESTFN, unlink, rmtree) | ||||
| from test.support import script_helper, threading_helper, requires_gil_enabled | ||||
| from test.support import script_helper, threading_helper | ||||
| 
 | ||||
| threading_helper.requires_working_threading(module=True) | ||||
| 
 | ||||
|  | @ -248,9 +248,6 @@ def test_concurrent_futures_circular_import(self): | |||
|                           'partial', 'cfimport.py') | ||||
|         script_helper.assert_python_ok(fn) | ||||
| 
 | ||||
|     # gh-118727 and gh-118729: pool_in_threads.py may crash in free-threaded | ||||
|     # builds, which can hang the Tsan test so temporarily skip it for now. | ||||
|     @requires_gil_enabled("gh-118727: test may crash in free-threaded builds") | ||||
|     def test_multiprocessing_pool_circular_import(self): | ||||
|         # Regression test for bpo-41567 | ||||
|         fn = os.path.join(os.path.dirname(__file__), | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)