代码之家  ›  专栏  ›  技术社区  ›  Andrew Pinkham

Python、Macport和缓冲区问题

  •  7
  • Andrew Pinkham  · 技术社区  · 9 年前

    如果这是一个错误的地方,我道歉-我不清楚问题是什么。

    当使用运行MacOX 10.10的Macports 2.3.3构建的Python版本时,我看到了一些非常有趣的行为。我已经完全重新安装了Macports,并在iMac和Macbook Air上复制了它,并创建了一个新用户,以确保它与我的环境无关。上周并没有发生这种情况,在这期间的某个时候,情况发生了相当大的变化。

    在我调用Python之前,一切都正常。

    $ python
    Python 3.4.3 (default, Aug 26 2015, 18:29:14) 
    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1+1
    >>> 2
    ^D>>> 
    

    这个 >>> 在输入结果之前打印,但在我告诉Python使用Control-D退出之后也打印。

    此时,所有输入将停止在终端中打印(iTerm2中也会发生同样的情况)。如果我键入 echo 'this is ouput; input is hidden' 我唯一看到的是:

    $ this is ouput; input is hidden
    

    如果我重新调用解释器,事情会变得更奇怪。

    $ Python 3.4.3 (default, Aug 26 2015, 18:29:14) 
    [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1+1
    >>> 2
    ^C
    KeyboardInterrupt
    >>> ^D
    >>> exit()
    >>> $ 
    

    正在打印Control-C(不是常规),而忽略了Control-D——我必须键入exit才能退出提示。

    使用重置终端 reset 可以消除所有问题,但与Python解释器交互仍然是一场噩梦。

    我可以在Python 2.7、3.3、3.4和3.5中复制这种行为,这让我相信我在错误的地方查找问题。

    Python的打包安装(来自Python网站)运行良好,不会表现出这种行为。

    $ python3
    Python 3.5.0 (v3.5.0:374f501f4567, Sep 12 2015, 11:00:19) 
    [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> 1+1
    2
    >>> 
    KeyboardInterrupt
    >>> ^D
    

    我被难住了。我根本不知道该在哪里寻求帮助。我该如何找出问题所在?

    我打开了一个 bug report on the Macport Trac 在意识到这个问题在这里可能会更好之前。

    1 回复  |  直到 9 年前
        1
  •  6
  •   eborisch    9 年前

    https://trac.macports.org/ticket/48807

    似乎是libedit/curses交互。编辑端口文件以使用readline解析。希望很快就能修复。