Skip to content

Commit 6e49661

Browse files
committed
Defer import of InteractiveConsole
1 parent 728455e commit 6e49661

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

cmd2/cmd2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import tempfile
4545
import traceback
4646
from typing import Callable, List, Optional, Union, Tuple
47-
from code import InteractiveConsole
4847

4948
import pyperclip
5049

@@ -2794,6 +2793,7 @@ def onecmd_plus_hooks(cmd_plus_args):
27942793
self.pystate['self'] = self
27952794

27962795
localvars = self.pystate
2796+
from code import InteractiveConsole
27972797
interp = InteractiveConsole(locals=localvars)
27982798
interp.runcode('import sys, os;sys.path.insert(0, os.getcwd())')
27992799

speedup_import.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,21 @@ to import the `cmd2` module.
3838

3939
## Defer unittest
4040

41-
In commit 8bc2c37a we deferring the import of `unittest` until we need it to
41+
In commit 8bc2c37a we defer the import of `unittest` until we need it to
4242
test a transcript.
4343
```
4444
$./mtime.sh ~/.pyenv/versions/cmd2-3.6/bin/python -c "import cmd2"
4545
100 iterations
4646
average: real 0.131 user 0.091 sys 0.030
4747
```
48+
49+
50+
## Defer InteractiveConsole from code
51+
52+
In commit f3346ba1 we defer the import of `InteractiveConsole` until the user
53+
wants to run the `py` command.
54+
```
55+
$ ./mtime.sh ~/.pyenv/versions/cmd2-3.6/bin/python -c "import cmd2"
56+
100 iterations
57+
average: real 0.131 user 0.090 sys 0.030
58+
```

0 commit comments

Comments
 (0)