Skip to content

Commit 751b193

Browse files
authored
[lldb] Remove pydoc import during script interpreter init (#6291)
The Python script interpreter imports `pydoc` during initialization, but this can be slow in some cases, and doesn't seem to be necessary any more. This can be slow because pydoc may execute shell commands (for example `xcrun` on macOS). The shell commands may have variable performance, depending on their caches and search space. The 2012 bug report for the original commit (f71a839) says the following: > "script help" in lldb pipes the help documentation through less(1) but there's some > problem with the key handling and often the keys you'd use to move in less (space to > move down a page, 'q' to quit) are not received by less (they're going to lldb > instead) This was resolved at the time by overriding `pydoc`'s pager to be the `plainpager` function. I have manually tested `script help(lldb.SBDebugger)` and found no issues with the pager, including using "space" for paging, "/" for searching, and "q" for quitting. The presumption is that lldb and/or Python have improved I/O handling that eliminates the original problem. The original bug report gave an ~/.lldbinit workaround: ``` script import pydoc; pydoc.pager = pydoc.plainpager ``` Note that calling Python's `help()` will import `pydoc`, but this will only happen for users who use `help()` from the `script` command. Differential Revision: https://reviews.llvm.org/D144138 (cherry picked from commit f1ddfa6)
1 parent 9ebc7bc commit 751b193

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lldb/source/Plugins/ScriptInterpreter/Python/ScriptInterpreterPython.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger)
437437
// do their task
438438
run_string.Clear();
439439
run_string.Printf(
440-
"run_one_line (%s, 'import lldb.formatters, lldb.formatters.cpp, pydoc')",
440+
"run_one_line (%s, 'import lldb.formatters, lldb.formatters.cpp')",
441441
m_dictionary_name.c_str());
442442
PyRun_SimpleString(run_string.GetData());
443443
run_string.Clear();
@@ -450,7 +450,7 @@ ScriptInterpreterPythonImpl::ScriptInterpreterPythonImpl(Debugger &debugger)
450450
run_string.Clear();
451451

452452
run_string.Printf("run_one_line (%s, 'lldb.debugger_unique_id = %" PRIu64
453-
"; pydoc.pager = pydoc.plainpager')",
453+
"')",
454454
m_dictionary_name.c_str(), m_debugger.GetID());
455455
PyRun_SimpleString(run_string.GetData());
456456
}

0 commit comments

Comments
 (0)