Emacs:Inferior-mode python-shell出现"滞后"

Mik*_*and 6 python emacs

我是一个Python(3.1.2)/ emacs(23.2)新手教我自己tkinter使用这里找到的pythonware教程.相关代码粘贴在问题下方.

问题:当我单击Hello按钮(应该调用say_hi函数)时,为什么劣质python shell(即我用Cc Cc启动的那个)等待执行say_hi打印功能,直到我a)单击退出按钮或b)关闭根小部件?当我在IDLE中尝试相同时,每次单击Hello按钮都会在IDLE python shell中立即打印,甚至在我单击Quit或关闭根小部件之前.

emacs运行Python shell(相对于IDLE)会导致这种"滞后"行为的方式有些怪癖吗?我已经注意到类似的emacs滞后与IDLE,因为我已经解决了Project Euler问题,但这是我见过的最明显的例子.

仅供参考:我使用python.el并且有一个相对干净的init.el ...

(setq python-python-command"d:/ bin/python31/python")

是我的init.el中唯一的一行.

谢谢,

麦克风

===开始代码===

from tkinter import *

class App:

    def __init__(self,master):

        frame = Frame(master)
        frame.pack()

        self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)
        self.button.pack(side=LEFT)

        self.hi_there = Button(frame, text="Hello", command=self.say_hi)
        self.hi_there.pack(side=LEFT)

    def say_hi(self):
        print("hi there, everyone!")

root = Tk()

app = App(root)

root.mainloop()
Run Code Online (Sandbox Code Playgroud)

msw*_*msw 4

我猜想,如果没有附加到 tty,Python 解释器(通过 C stdio)会切换到从行缓冲的块缓冲,并且在关闭之前不会刷新标准输出。os.isatty(1)在“Inferior Python:run Shell Compile”缓冲区中运行会返回 false,从而增加了此猜测的权重。

def say_hi(self):
    print("hi there, everyone!")
    sys.stdout.flush()
Run Code Online (Sandbox Code Playgroud)

可能会有所作为。