File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 33import  pickle 
44from  textwrap  import  dedent 
55import  threading 
6+ import  tracemalloc 
67import  unittest 
78
89from  test  import  support 
@@ -1098,5 +1099,34 @@ def script(spam, /):
10981099                _interpreters .run_func (self .id , script )
10991100
11001101
1102+ class  TestTracemallocWithInterpreters (TestBase ):
1103+     def  setUp (self ):
1104+         if  tracemalloc .is_tracing ():
1105+             self .skipTest ("tracemalloc must be stopped before the test" )
1106+ 
1107+         tracemalloc .start (1 )
1108+ 
1109+     def  tearDown (self ):
1110+         tracemalloc .stop ()
1111+         super ().tearDown ()
1112+ 
1113+     def  test_trace_interp_start_frames (self ):
1114+         interpid  =  _interpreters .create ()
1115+         # check that tracing captures frames created by the new interpreter 
1116+         self .assertNotEqual (
1117+             tracemalloc .take_snapshot ().statistics ("filename" ),
1118+             []
1119+         )
1120+         _interpreters .destroy (interpid )
1121+ 
1122+     def  test_trace_interp_frames (self ):
1123+         interpid  =  _interpreters .create ()
1124+         _interpreters .run_string (interpid , "def f(): ..." )
1125+         stats  =  tracemalloc .take_snapshot ().statistics ("filename" )
1126+         # check that the last frame is the string run in the interpreter 
1127+         self .assertEqual (stats [- 1 ].traceback ._frames [0 ][0 ], "<string>" )
1128+         _interpreters .destroy (interpid )
1129+ 
1130+ 
11011131if  __name__  ==  '__main__' :
11021132    unittest .main ()
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments