There was an error while loading. Please reload this page.
1 parent 630df37 commit 689ada7Copy full SHA for 689ada7
1 file changed
Lib/linecache.py
@@ -5,9 +5,6 @@
5
that name.
6
"""
7
8
-import sys
9
-import os
10
-
11
__all__ = ["getline", "clearcache", "checkcache", "lazycache"]
12
13
@@ -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__
+ try:
+ # This import can fail if the interpreter is shutting down
+ import os
69
+ except ImportError:
70
+ return
71
try:
72
stat = os.stat(fullname)
73
except OSError:
@@ -76,6 +78,12 @@ def checkcache(filename=None):
76
78
77
79
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
85
+ import sys
86
+
87
"""Update a cache entry and return its list of lines.
88
If something's wrong, print a message, discard the cache entry,
89
and return an empty list."""
0 commit comments