3
3
import warnings
4
4
from inspect import isabstract
5
5
from typing import Any
6
+ import linecache
6
7
7
8
from test import support
8
9
from test .support import os_helper
@@ -73,6 +74,7 @@ def runtest_refleak(test_name, test_func,
73
74
ps = copyreg .dispatch_table .copy ()
74
75
pic = sys .path_importer_cache .copy ()
75
76
zdc : dict [str , Any ] | None
77
+ linecache_data = linecache .cache .copy (), linecache ._interactive_cache .copy ()
76
78
try :
77
79
import zipimport
78
80
except ImportError :
@@ -122,7 +124,7 @@ def get_pooled_int(value):
122
124
123
125
xml_filename = 'refleak-xml.tmp'
124
126
result = None
125
- dash_R_cleanup (fs , ps , pic , zdc , abcs )
127
+ dash_R_cleanup (fs , ps , pic , zdc , abcs , linecache_data )
126
128
127
129
for i in rep_range :
128
130
support .gc_collect ()
@@ -134,7 +136,7 @@ def get_pooled_int(value):
134
136
refleak_helper ._hunting_for_refleaks = current
135
137
136
138
save_support_xml (xml_filename )
137
- dash_R_cleanup (fs , ps , pic , zdc , abcs )
139
+ dash_R_cleanup (fs , ps , pic , zdc , abcs , linecache_data )
138
140
support .gc_collect ()
139
141
140
142
# Read memory statistics immediately after the garbage collection.
@@ -223,7 +225,7 @@ def check_fd_deltas(deltas):
223
225
return (failed , result )
224
226
225
227
226
- def dash_R_cleanup (fs , ps , pic , zdc , abcs ):
228
+ def dash_R_cleanup (fs , ps , pic , zdc , abcs , linecache_data ):
227
229
import copyreg
228
230
import collections .abc
229
231
@@ -233,6 +235,11 @@ def dash_R_cleanup(fs, ps, pic, zdc, abcs):
233
235
copyreg .dispatch_table .update (ps )
234
236
sys .path_importer_cache .clear ()
235
237
sys .path_importer_cache .update (pic )
238
+ lcache , linteractive = linecache_data
239
+ linecache ._interactive_cache .clear ()
240
+ linecache ._interactive_cache .update (linteractive )
241
+ linecache .cache .clear ()
242
+ linecache .cache .update (lcache )
236
243
try :
237
244
import zipimport
238
245
except ImportError :
0 commit comments