mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	gh-84559: Change the multiprocessing start method default to forkserver (GH-101556)
				
					
				
			Change the default multiprocessing start method away from fork to forkserver or spawn on the remaining platforms where it was fork. See the issue for context. This makes the default far more thread safe (other than for people spawning threads at import time... - don't do that!). Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									83e5dc0f4d
								
							
						
					
					
						commit
						b65f2cdfa7
					
				
					 7 changed files with 75 additions and 33 deletions
				
			
		|  | @ -259,13 +259,12 @@ def get_start_method(self, allow_none=False): | |||
| 
 | ||||
|     def get_all_start_methods(self): | ||||
|         """Returns a list of the supported start methods, default first.""" | ||||
|         if sys.platform == 'win32': | ||||
|             return ['spawn'] | ||||
|         else: | ||||
|             methods = ['spawn', 'fork'] if sys.platform == 'darwin' else ['fork', 'spawn'] | ||||
|             if reduction.HAVE_SEND_HANDLE: | ||||
|                 methods.append('forkserver') | ||||
|             return methods | ||||
|         default = self._default_context.get_start_method() | ||||
|         start_method_names = [default] | ||||
|         start_method_names.extend( | ||||
|             name for name in _concrete_contexts if name != default | ||||
|         ) | ||||
|         return start_method_names | ||||
| 
 | ||||
| 
 | ||||
| # | ||||
|  | @ -320,14 +319,15 @@ def _check_available(self): | |||
|         'spawn': SpawnContext(), | ||||
|         'forkserver': ForkServerContext(), | ||||
|     } | ||||
|     if sys.platform == 'darwin': | ||||
|         # bpo-33725: running arbitrary code after fork() is no longer reliable | ||||
|         # on macOS since macOS 10.14 (Mojave). Use spawn by default instead. | ||||
|         _default_context = DefaultContext(_concrete_contexts['spawn']) | ||||
|     # bpo-33725: running arbitrary code after fork() is no longer reliable | ||||
|     # on macOS since macOS 10.14 (Mojave). Use spawn by default instead. | ||||
|     # gh-84559: We changed everyones default to a thread safeish one in 3.14. | ||||
|     if reduction.HAVE_SEND_HANDLE and sys.platform != 'darwin': | ||||
|         _default_context = DefaultContext(_concrete_contexts['forkserver']) | ||||
|     else: | ||||
|         _default_context = DefaultContext(_concrete_contexts['fork']) | ||||
|         _default_context = DefaultContext(_concrete_contexts['spawn']) | ||||
| 
 | ||||
| else: | ||||
| else:  # Windows | ||||
| 
 | ||||
|     class SpawnProcess(process.BaseProcess): | ||||
|         _start_method = 'spawn' | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Gregory P. Smith
						Gregory P. Smith