IPython无缓冲模式

5 投票
2 回答
1091 浏览
提问于 2025-04-15 15:07

有没有办法让IPython以无缓冲模式运行呢?

就像用python -u命令可以让标准的Python命令行不使用缓冲一样。

2 个回答

0

试试这个:

python -u `which ipython`

不过我不确定这个是否有效。

2

来自Python的手册:

   -u     Force stdin, stdout and stderr to be totally unbuffered.  On systems
          where it matters, also put stdin, stdout and stderr in binary mode.
          Note that there is internal buffering in xreadlines(), readlines()
          and file-object iterators ("for line in sys.stdin") which is not
          influenced by this option.  To work around this, you will want to use
          "sys.stdin.readline()" inside a "while 1:" loop.

如果使用无缓冲模式会影响到readline功能,那么它肯定会更严重地影响到iPython提供的那些神奇的编辑和自动补全功能。我觉得这就是为什么在iPython中没有这个命令行选项的原因。

撰写回答