diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-10-24 20:23:42 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-10-24 20:23:42 (GMT) |
commit | 7cb11fa89034a06dcad58b65a0321dae9171dbea (patch) | |
tree | f24a8ef3575bbd3cadf71773b4ca8a5b75b92aa4 /Lib | |
parent | f740d467bf4c4552cf437d41838a75fb2dc168d8 (diff) | |
download | cpython-7cb11fa89034a06dcad58b65a0321dae9171dbea.zip cpython-7cb11fa89034a06dcad58b65a0321dae9171dbea.tar.gz cpython-7cb11fa89034a06dcad58b65a0321dae9171dbea.tar.bz2 |
Close #19379: Lazily import linecache in the warnings module, to make startup with warnings faster until a warning gets printed.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/warnings.py | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/Lib/warnings.py b/Lib/warnings.py index b05a08e..a427e35 100644 --- a/Lib/warnings.py +++ b/Lib/warnings.py @@ -1,9 +1,5 @@ """Python part of the warnings subsystem.""" -# Note: function level imports should *not* be used -# in this module as it may cause import lock deadlock. -# See bug 683658. -import linecache import sys __all__ = ["warn", "showwarning", "formatwarning", "filterwarnings", @@ -21,6 +17,7 @@ def showwarning(message, category, filename, lineno, file=None, line=None): def formatwarning(message, category, filename, lineno, line=None): """Function to format a warning the standard way.""" + import linecache s = "%s:%s: %s: %s\n" % (filename, lineno, category.__name__, message) line = linecache.getline(filename, lineno) if line is None else line if line: @@ -233,6 +230,7 @@ def warn_explicit(message, category, filename, lineno, # Prime the linecache for formatting, in case the # "file" is actually in a zipfile or something. + import linecache linecache.getlines(filename, module_globals) if action == "error": |