输入的终端显示不同步 while/after 使用 python? (临时修复 = `reset`)

Terminal display of input goes out of sync while/after using python? (temporary fix = `reset`)

每次我 运行 pythonpython3 使用交互式控制台时,提示的显示在第一次或第二次交互后几乎立即不同步:

>>> [1,2,3]
>>> [1, 2, 3]
print('hi')
>>> hi

然后,当我退出 python 时,此行为会延续到 bash,此外,当您键入时,屏幕上不会出现任何内容,但它仍然会 运行.在下面的例子中,我输入了 date 然后是 history | tail -n3:

$ Thu Oct  8 07:55:47 CEST 2015
$   488  python
  489  date
  490  history | tail -n3

然而,输入 reset 后,一切恢复正常。

不用说,这种行为很烦人。是什么原因,我该如何解决?

我在 OS X 上。使用 iTerm 或内置 Terminal.app 都给出相同的行为。我的 python 构建来自 macports/usr/bin/python(python 2.7.2,包含在 OS X 中)不存在此问题。

==============================

编辑:如果我使用zsh,那么python仍然有问题,但退出后zsh一切正常python.

$TERMbashzsh 中都是 xterm-256color

尝试 shell 中的 stty sane 命令。

正如我在 AskDifferent there was a bug in recent python builds under Macports when the question was written due to this Macports bug 中的回答一样,因为它不包括 readline(出于许可原因)

现在已通过制作 +readline 变体并将其设为默认值来解决这个问题

@Mark 有解释。

至于修复:

port selfupdate
# port install python(26|27|34|35) +readline
port install python27 +readline