File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 55that name.
66"""
77
8- import sys
9- import os
10-
118__all__ = ["getline" , "clearcache" , "checkcache" , "lazycache" ]
129
1310
@@ -67,15 +64,25 @@ def checkcache(filename=None):
6764 if mtime is None :
6865 continue # no-op for files loaded via a __loader__
6966 try :
67+ # This import can fail if the interpreter is shutting down
68+ import os
7069 stat = os .stat (fullname )
7170 except OSError :
7271 cache .pop (filename , None )
7372 continue
73+ except ImportError :
74+ return
7475 if size != stat .st_size or mtime != stat .st_mtime :
7576 cache .pop (filename , None )
7677
7778
7879def updatecache (filename , module_globals = None ):
80+ # These imports are not at top level because linecache is in the critical
81+ # path of the interpreter startup and importing os and sys take a lot of time
82+ # and slow down the startup sequence.
83+ import os
84+ import sys
85+
7986 """Update a cache entry and return its list of lines.
8087 If something's wrong, print a message, discard the cache entry,
8188 and return an empty list."""
You can’t perform that action at this time.
0 commit comments