mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 13:41:24 +00:00 
			
		
		
		
	Prevent test_inspect from keeping alive a ton of frames and local variables by way of a global variable keeping a reference to a traceback.
Should fix some buildbot failures.
This commit is contained in:
		
							parent
							
								
									48114b952b
								
							
						
					
					
						commit
						d5a1a21a89
					
				
					 2 changed files with 16 additions and 13 deletions
				
			
		|  | @ -101,7 +101,7 @@ def test_lock_lifetime(self): | ||||||
| 
 | 
 | ||||||
|     def test_all_locks(self): |     def test_all_locks(self): | ||||||
|         support.gc_collect() |         support.gc_collect() | ||||||
|         self.assertEqual(0, len(_bootstrap._module_locks)) |         self.assertEqual(0, len(_bootstrap._module_locks), _bootstrap._module_locks) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @support.reap_threads | @support.reap_threads | ||||||
|  |  | ||||||
|  | @ -41,11 +41,6 @@ def revise(filename, *args): | ||||||
| 
 | 
 | ||||||
| import builtins | import builtins | ||||||
| 
 | 
 | ||||||
| try: |  | ||||||
|     1/0 |  | ||||||
| except: |  | ||||||
|     tb = sys.exc_info()[2] |  | ||||||
| 
 |  | ||||||
| git = mod.StupidGit() | git = mod.StupidGit() | ||||||
| 
 | 
 | ||||||
| class IsTestBase(unittest.TestCase): | class IsTestBase(unittest.TestCase): | ||||||
|  | @ -79,23 +74,31 @@ def test_sixteen(self): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     def test_excluding_predicates(self): |     def test_excluding_predicates(self): | ||||||
|  |         global tb | ||||||
|         self.istest(inspect.isbuiltin, 'sys.exit') |         self.istest(inspect.isbuiltin, 'sys.exit') | ||||||
|         self.istest(inspect.isbuiltin, '[].append') |         self.istest(inspect.isbuiltin, '[].append') | ||||||
|         self.istest(inspect.iscode, 'mod.spam.__code__') |         self.istest(inspect.iscode, 'mod.spam.__code__') | ||||||
|         self.istest(inspect.isframe, 'tb.tb_frame') |         try: | ||||||
|  |             1/0 | ||||||
|  |         except: | ||||||
|  |             tb = sys.exc_info()[2] | ||||||
|  |             self.istest(inspect.isframe, 'tb.tb_frame') | ||||||
|  |             self.istest(inspect.istraceback, 'tb') | ||||||
|  |             if hasattr(types, 'GetSetDescriptorType'): | ||||||
|  |                 self.istest(inspect.isgetsetdescriptor, | ||||||
|  |                             'type(tb.tb_frame).f_locals') | ||||||
|  |             else: | ||||||
|  |                 self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) | ||||||
|  |         finally: | ||||||
|  |             # Clear traceback and all the frames and local variables hanging to it. | ||||||
|  |             tb = None | ||||||
|         self.istest(inspect.isfunction, 'mod.spam') |         self.istest(inspect.isfunction, 'mod.spam') | ||||||
|         self.istest(inspect.isfunction, 'mod.StupidGit.abuse') |         self.istest(inspect.isfunction, 'mod.StupidGit.abuse') | ||||||
|         self.istest(inspect.ismethod, 'git.argue') |         self.istest(inspect.ismethod, 'git.argue') | ||||||
|         self.istest(inspect.ismodule, 'mod') |         self.istest(inspect.ismodule, 'mod') | ||||||
|         self.istest(inspect.istraceback, 'tb') |  | ||||||
|         self.istest(inspect.isdatadescriptor, 'collections.defaultdict.default_factory') |         self.istest(inspect.isdatadescriptor, 'collections.defaultdict.default_factory') | ||||||
|         self.istest(inspect.isgenerator, '(x for x in range(2))') |         self.istest(inspect.isgenerator, '(x for x in range(2))') | ||||||
|         self.istest(inspect.isgeneratorfunction, 'generator_function_example') |         self.istest(inspect.isgeneratorfunction, 'generator_function_example') | ||||||
|         if hasattr(types, 'GetSetDescriptorType'): |  | ||||||
|             self.istest(inspect.isgetsetdescriptor, |  | ||||||
|                         'type(tb.tb_frame).f_locals') |  | ||||||
|         else: |  | ||||||
|             self.assertFalse(inspect.isgetsetdescriptor(type(tb.tb_frame).f_locals)) |  | ||||||
|         if hasattr(types, 'MemberDescriptorType'): |         if hasattr(types, 'MemberDescriptorType'): | ||||||
|             self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') |             self.istest(inspect.ismemberdescriptor, 'datetime.timedelta.days') | ||||||
|         else: |         else: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Antoine Pitrou
						Antoine Pitrou