File tree 1 file changed +11
-3
lines changed
1 file changed +11
-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
@@ -66,6 +63,11 @@ def checkcache(filename=None):
66
63
size , mtime , lines , fullname = entry
67
64
if mtime is None :
68
65
continue # no-op for files loaded via a __loader__
66
+ try :
67
+ # This import can fail if the interpreter is shutting down
68
+ import os
69
+ except ImportError :
70
+ return
69
71
try :
70
72
stat = os .stat (fullname )
71
73
except OSError :
@@ -76,6 +78,12 @@ def checkcache(filename=None):
76
78
77
79
78
80
def updatecache (filename , module_globals = None ):
81
+ # These imports are not at top level because linecache is in the critical
82
+ # path of the interpreter startup and importing os and sys take a lot of time
83
+ # and slow down the startup sequence.
84
+ import os
85
+ import sys
86
+
79
87
"""Update a cache entry and return its list of lines.
80
88
If something's wrong, print a message, discard the cache entry,
81
89
and return an empty list."""
You can’t perform that action at this time.
0 commit comments