开发者

Emacs: Inferior-mode python-shell appears "lagged"

I'm a Python(3.1.2)/emacs(23.2) newbie teaching myself tkinter using the pythonware tutorial found here. Relevant code is pasted below the question.

Question: when I click the Hello button (which should call the say_hi function) why does the inferior python shell (i.e. the one I kicked off wit开发者_StackOverflow社区h C-c C-c) wait to execute the say_hi print function until I either a) click the Quit button or b) close the root widget down? When I try the same in IDLE, each click of the Hello button produces an immediate print in the IDLE python shell, even before I click Quit or close the root widget.

Is there some quirk in the way emacs runs the Python shell (vs. IDLE) that causes this "lagged" behavior? I've noticed similar emacs lags vs. IDLE as I've worked through Project Euler problems, but this is the clearest example I've seen yet.

FYI: I use python.el and have a relatively clean init.el...

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

is the only line in my init.el.

Thanks,

Mike

=== Begin Code===

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()


I'd guess that not being attached to a tty, the Python interpreter (via C stdio) switches to block buffered from line buffered and doesn't flush stdout until it closes. Running os.isatty(1) in an "Inferior Python:run Shell Compile" buffer returns false, thus adding weight to this guess.

def say_hi(self):
    print("hi there, everyone!")
    sys.stdout.flush()

May make a difference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜