mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	run_module shouldn't hold the import lock when running a script
This commit is contained in:
		
							parent
							
								
									cdb7948f97
								
							
						
					
					
						commit
						c841bb6b63
					
				
					 1 changed files with 9 additions and 13 deletions
				
			
		
							
								
								
									
										22
									
								
								Lib/runpy.py
									
										
									
									
									
								
							
							
						
						
									
										22
									
								
								Lib/runpy.py
									
										
									
									
									
								
							|  | @ -379,21 +379,17 @@ def _run_module_code(code, init_globals=None, | |||
|         restore_module = mod_name in sys.modules | ||||
|         if restore_module: | ||||
|             saved_module = sys.modules[mod_name] | ||||
|         imp.acquire_lock() | ||||
|         sys.argv[0] = mod_fname | ||||
|         sys.modules[mod_name] = temp_module | ||||
|         try: | ||||
|             sys.argv[0] = mod_fname | ||||
|             sys.modules[mod_name] = temp_module | ||||
|             try: | ||||
|                 _run_code(code, mod_globals, init_globals, | ||||
|                           mod_name, mod_fname, mod_loader) | ||||
|             finally: | ||||
|                 sys.argv[0] = saved_argv0 | ||||
|                 if restore_module: | ||||
|                     sys.modules[mod_name] = saved_module | ||||
|                 else: | ||||
|                     del sys.modules[mod_name] | ||||
|             _run_code(code, mod_globals, init_globals, | ||||
|                       mod_name, mod_fname, mod_loader) | ||||
|         finally: | ||||
|             imp.release_lock() | ||||
|             sys.argv[0] = saved_argv0 | ||||
|         if restore_module: | ||||
|                 sys.modules[mod_name] = saved_module | ||||
|         else: | ||||
|                 del sys.modules[mod_name] | ||||
|         # Copy the globals of the temporary module, as they | ||||
|         # may be cleared when the temporary module goes away | ||||
|         return mod_globals.copy() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nick Coghlan
						Nick Coghlan