Skip to content

Commit

Permalink
Switch from 'embedding' to 'starting' IPython
Browse files Browse the repository at this point in the history
Embedding IPython results in issues where import statements and other
globals changes in the shell environment don't work as expected.[1]
As an example, the following commands result in a NameError:

In [1]: import time

In [2]: def foo():
   ...:     print(time.time())
   ...:

In [3]: foo()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-3-c19b6d9633cf> in <module>
----> 1 foo()

<ipython-input-2-a038e7f91c93> in foo()
      1 def foo():
----> 2     print(time.time())
      3

NameError: name 'time' is not defined

By switching to use "start_ipython()" instead, we get an environment
more similar to what we get by running `ipython` directly.

[1] ipython/ipython#62
  • Loading branch information
kemitche committed Oct 28, 2020
1 parent 14eaf99 commit 4f2efd2
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions baseplate/server/__init__.py
Expand Up @@ -374,11 +374,8 @@ def load_and_run_shell() -> None:

try:
# try to use IPython if possible
from IPython.terminal.embed import InteractiveShellEmbed
from IPython.core.interactiveshell import DummyMod

shell = InteractiveShellEmbed(banner2=banner)
shell(local_ns=env, module=DummyMod())
from IPython import start_ipython
start_ipython(argv=[], user_ns=env)
except ImportError:
import code

Expand Down

0 comments on commit 4f2efd2

Please sign in to comment.