终端不再回声的根本原因是什么?

时间:2021-02-06 01:45:44

I am currently trying to use editline with python on linux, in place of readline. Overall it works, except that I get this behavior. This is verbatim from my terminal

我目前正在尝试在linux上使用带有python的editline,而不是readline。总的来说它有效,除了我得到这种行为。这是我终端的逐字记录

   bash> python
   Python 2.7.2 (default, Feb 20 2015, 13:19:18) 
   [GCC 4.6.3] on linux3
   Type "help", "copyright", "credits" or "license" for more  information. 
1  >>> 
2  >>> hello
3  >>> Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
   NameError: name 'hello' is not defined
4

In 1, I press enter. it seems to work. in 2 I use an undefined name just to test. Note that in 3 I get a prompt before the traceback, and in 4 I have no prompt. In practice, the printing order is all screwed up. Similar things happen if I use print

在1,我按回车键。它似乎工作。在2我使用一个未定义的名称来测试。请注意,在3中我在回溯之前得到提示,在4中我没有提示。在实践中,打印顺序全部搞砸了。如果我使用print,会发生类似的事情

 >>> print "hello"
 >>> hello

Now to the more important thing. When I quit the python executable with ^D or quit() I get this situation

现在更重要的是。当我用^ D或quit()退出python可执行文件时,我得到了这种情况

 1 ^D>>> 
 2 bash> bash> bash> bash> bash> bash> bash> bash> bash> bash> bash> bash> The program 'hello' can be found in the following packages:
    * hello
    * hello-debhelper
    Try: sudo apt-get install <selected package>
 3 bash> bash> bash> bash> bash> bash> bash> 

in 1 I press control D. Note that the python prompt shows again. I get to the bash prompt. Now, in 2 if I press enter multiple times I get the prompt again and again. If I type "hello" followed by enter I don't get any echo of the characters. Same in 3.

在1我按下控制D.注意python提示再次显示。我进入bash提示符。现在,在2中,如果我多次按下输入,我会一次又一次地得到提示。如果我输入“你好”然后输入我不会得到任何字符的回声。同样在3。

If I use "reset" i restore the terminal to a sane state, but the point is that python, editline, or their interaction screws up the terminal somehow. I've seen this behavior also with ncurses when incorrectly deinitialized, but I am not sure about the underlying cause in terms of terminal settings that may have been altered.

如果我使用“重置”我将终端恢复到一个理智的状态,但重点是python,editline或他们的交互以某种方式搞砸了终端。我在错误地取消初始化时也看到了ncurses的这种行为,但我不确定可能已经改变的终端设置方面的根本原因。

I am trying to debug and fix the problem, so I would value any information about what exactly is happening at the terminal level that ruins it. Once I know which routine is doing the damage, I can trace the problem in more detail.

我正在尝试调试并修复问题,所以我会重视有关在终端级别发生的事情的任何信息,这些信息会破坏它。一旦我知道哪个例程正在造成损害,我就可以更详细地追踪问题。

1 个解决方案

#1


0  

Aparently python/editline combination are messing around with the output and probablay error streams.

显然python / editline组合正在弄乱输出和probablay错误流。

My guess is that buffering mode is modified by somebody incorrectly to line-buffered mode (or full-buffered mode) for output stream.

我的猜测是缓冲模式被某人错误地修改为输出流的行缓冲模式(或全缓冲模式)。

Normally the error stream is in unbuffered mode. Probabaly thats why you are seeing the error message, but not the info (standard output)

通常,错误流处于无缓冲模式。 Probabaly这就是为什么你看到错误信息,而不是信息(标准输出)

When your terminating python kernel automatically flushes the content of the standard output buffer, so you see final messages as you described.

当终止python内核自动刷新标准输出缓冲区的内容时,您可以看到所描述的最终消息。

Well to figure out what exactly is happening you need to debug python interpretator.

好了解你究竟发生了什么,你需要调试python解释器。

#1


0  

Aparently python/editline combination are messing around with the output and probablay error streams.

显然python / editline组合正在弄乱输出和probablay错误流。

My guess is that buffering mode is modified by somebody incorrectly to line-buffered mode (or full-buffered mode) for output stream.

我的猜测是缓冲模式被某人错误地修改为输出流的行缓冲模式(或全缓冲模式)。

Normally the error stream is in unbuffered mode. Probabaly thats why you are seeing the error message, but not the info (standard output)

通常,错误流处于无缓冲模式。 Probabaly这就是为什么你看到错误信息,而不是信息(标准输出)

When your terminating python kernel automatically flushes the content of the standard output buffer, so you see final messages as you described.

当终止python内核自动刷新标准输出缓冲区的内容时,您可以看到所描述的最终消息。

Well to figure out what exactly is happening you need to debug python interpretator.

好了解你究竟发生了什么,你需要调试python解释器。