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

Function clear_caches

Lib/test/libregrtest/utils.py:178–314  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

176
177
178def clear_caches():
179 # Clear the warnings registry, so they can be displayed again
180 for mod in sys.modules.values():
181 if hasattr(mod, '__warningregistry__'):
182 del mod.__warningregistry__
183
184 # Flush standard output, so that buffered data is sent to the OS and
185 # associated Python objects are reclaimed.
186 for stream in (sys.stdout, sys.stderr, sys.__stdout__, sys.__stderr__):
187 if stream is not None:
188 stream.flush()
189
190 try:
191 re = sys.modules['re']
192 except KeyError:
193 pass
194 else:
195 re.purge()
196
197 try:
198 _strptime = sys.modules['_strptime']
199 except KeyError:
200 pass
201 else:
202 _strptime._regex_cache.clear()
203
204 try:
205 urllib_parse = sys.modules['urllib.parse']
206 except KeyError:
207 pass
208 else:
209 urllib_parse.clear_cache()
210
211 try:
212 urllib_request = sys.modules['urllib.request']
213 except KeyError:
214 pass
215 else:
216 urllib_request.urlcleanup()
217
218 try:
219 linecache = sys.modules['linecache']
220 except KeyError:
221 pass
222 else:
223 linecache.clearcache()
224
225 try:
226 mimetypes = sys.modules['mimetypes']
227 except KeyError:
228 pass
229 else:
230 mimetypes._default_mime_types()
231
232 try:
233 filecmp = sys.modules['filecmp']
234 except KeyError:
235 pass

Callers 2

dash_R_cleanupFunction · 0.85
_runtest_env_changed_excFunction · 0.85

Calls 9

fFunction · 0.50
filterFunction · 0.50
valuesMethod · 0.45
flushMethod · 0.45
clearMethod · 0.45
clear_cacheMethod · 0.45
_abc_caches_clearMethod · 0.45
registerMethod · 0.45
unregisterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…