File tree 1 file changed +10
-3
lines changed
1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 5
5
that name.
6
6
"""
7
7
8
- import sys
9
- import os
10
-
11
8
__all__ = ["getline" , "clearcache" , "checkcache" , "lazycache" ]
12
9
13
10
@@ -67,15 +64,25 @@ def checkcache(filename=None):
67
64
if mtime is None :
68
65
continue # no-op for files loaded via a __loader__
69
66
try :
67
+ # This import can fail if the interpreter is shutting down
68
+ import os
70
69
stat = os .stat (fullname )
71
70
except OSError :
72
71
cache .pop (filename , None )
73
72
continue
73
+ except ImportError :
74
+ return
74
75
if size != stat .st_size or mtime != stat .st_mtime :
75
76
cache .pop (filename , None )
76
77
77
78
78
79
def 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
+
79
86
"""Update a cache entry and return its list of lines.
80
87
If something's wrong, print a message, discard the cache entry,
81
88
and return an empty list."""
You can’t perform that action at this time.
0 commit comments