MCPcopy Index your code
hub / github.com/python/cpython / dash_R_cleanup

Function dash_R_cleanup

Lib/test/libregrtest/refleak.py:239–282  ·  view source on GitHub ↗
(fs, ps, pic, zdc, abcs, linecache_data)

Source from the content-addressed store, hash-verified

237
238
239def dash_R_cleanup(fs, ps, pic, zdc, abcs, linecache_data):
240 import copyreg
241 import collections.abc
242
243 # Restore some original values.
244 warnings.filters[:] = fs
245 copyreg.dispatch_table.clear()
246 copyreg.dispatch_table.update(ps)
247 sys.path_importer_cache.clear()
248 sys.path_importer_cache.update(pic)
249 lcache, linteractive = linecache_data
250 linecache._interactive_cache.clear()
251 linecache._interactive_cache.update(linteractive)
252 linecache.cache.clear()
253 linecache.cache.update(lcache)
254 try:
255 import zipimport
256 except ImportError:
257 pass # Run unmodified on platforms without zipimport support
258 else:
259 zipimport._zip_directory_cache.clear()
260 zipimport._zip_directory_cache.update(zdc)
261
262 # Clear ABC registries, restoring previously saved ABC registries.
263 abs_classes = [getattr(collections.abc, a) for a in collections.abc.__all__]
264 with warnings.catch_warnings(action='ignore', category=DeprecationWarning):
265 abs_classes.append(collections.abc.ByteString)
266 abs_classes = filter(isabstract, abs_classes)
267 for abc in abs_classes:
268 for obj in abc.__subclasses__() + [abc]:
269 refs = abcs.get(obj, None)
270 if refs is not None:
271 obj._abc_registry_clear()
272 for ref in refs:
273 subclass = ref()
274 if subclass is not None:
275 obj.register(subclass)
276 obj._abc_caches_clear()
277
278 # Clear caches
279 clear_caches()
280
281 # Clear other caches last (previous function calls can re-populate them):
282 sys._clear_internal_caches()
283
284
285def warm_caches() -> None:

Callers 1

runtest_refleakFunction · 0.85

Calls 9

clear_cachesFunction · 0.85
filterFunction · 0.50
clearMethod · 0.45
updateMethod · 0.45
appendMethod · 0.45
getMethod · 0.45
_abc_registry_clearMethod · 0.45
registerMethod · 0.45
_abc_caches_clearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…