mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Fix initialization of the faulthandler module
faulthandler requires the importlib if "-X faulthandler" option is present on the command line, so initialize faulthandler after importlib. Add also an unit test.
This commit is contained in:
		
							parent
							
								
									60622ed12a
								
							
						
					
					
						commit
						d5698cbbca
					
				
					 2 changed files with 19 additions and 4 deletions
				
			
		|  | @ -7,6 +7,7 @@ | ||||||
| import subprocess | import subprocess | ||||||
| import sys | import sys | ||||||
| from test import support, script_helper | from test import support, script_helper | ||||||
|  | from test.script_helper import assert_python_ok | ||||||
| import tempfile | import tempfile | ||||||
| import unittest | import unittest | ||||||
| 
 | 
 | ||||||
|  | @ -256,6 +257,20 @@ def test_is_enabled(self): | ||||||
|         finally: |         finally: | ||||||
|             sys.stderr = orig_stderr |             sys.stderr = orig_stderr | ||||||
| 
 | 
 | ||||||
|  |     def test_disabled_by_default(self): | ||||||
|  |         # By default, the module should be disabled | ||||||
|  |         code = "import faulthandler; print(faulthandler.is_enabled())" | ||||||
|  |         rc, stdout, stderr = assert_python_ok("-c", code) | ||||||
|  |         stdout = (stdout + stderr).strip() | ||||||
|  |         self.assertEqual(stdout, b"False") | ||||||
|  | 
 | ||||||
|  |     def test_sys_xoptions(self): | ||||||
|  |         # Test python -X faulthandler | ||||||
|  |         code = "import faulthandler; print(faulthandler.is_enabled())" | ||||||
|  |         rc, stdout, stderr = assert_python_ok("-X", "faulthandler", "-c", code) | ||||||
|  |         stdout = (stdout + stderr).strip() | ||||||
|  |         self.assertEqual(stdout, b"True") | ||||||
|  | 
 | ||||||
|     def check_dump_traceback(self, filename): |     def check_dump_traceback(self, filename): | ||||||
|         """ |         """ | ||||||
|         Explicitly call dump_traceback() function and check its output. |         Explicitly call dump_traceback() function and check its output. | ||||||
|  |  | ||||||
|  | @ -356,10 +356,6 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib) | ||||||
| 
 | 
 | ||||||
|     _PyImportHooks_Init(); |     _PyImportHooks_Init(); | ||||||
| 
 | 
 | ||||||
|     /* initialize the faulthandler module */ |  | ||||||
|     if (_PyFaulthandler_Init()) |  | ||||||
|         Py_FatalError("Py_Initialize: can't initialize faulthandler"); |  | ||||||
| 
 |  | ||||||
|     /* Initialize _warnings. */ |     /* Initialize _warnings. */ | ||||||
|     _PyWarnings_Init(); |     _PyWarnings_Init(); | ||||||
| 
 | 
 | ||||||
|  | @ -368,6 +364,10 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib) | ||||||
| 
 | 
 | ||||||
|     import_init(interp, sysmod); |     import_init(interp, sysmod); | ||||||
| 
 | 
 | ||||||
|  |     /* initialize the faulthandler module */ | ||||||
|  |     if (_PyFaulthandler_Init()) | ||||||
|  |         Py_FatalError("Py_Initialize: can't initialize faulthandler"); | ||||||
|  | 
 | ||||||
|     _PyTime_Init(); |     _PyTime_Init(); | ||||||
| 
 | 
 | ||||||
|     if (initfsencoding(interp) < 0) |     if (initfsencoding(interp) < 0) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner