本文介绍了Emacs:下模式python-shell出现“滞后”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个Python(3.1.2)/ emacs(23.2)新手教我自己的tkinter使用pythonware教程发现。



问题:当我点击Hello按钮(应该调用say_hi函数)为什么下面的python shell(即一个I踢Cc Cc)等待执行say_hi打印功能,直到我或者a)单击退出按钮或b)关闭根部件下来?当我在IDLE中尝试相同时,即使在我单击退出或关闭根窗口小部件之前,Hello按钮的每次点击都会在IDLE python shell中立即打印。



Emacs运行Python shell(而不是IDLE)会导致这种滞后行为的方式有什么奇怪吗?我已经注意到类似的emacs滞后与IDLE,因为我已经通过Project Euler问题,但这是我见过的最清楚的例子。



FYI:I使用python.el并且有一个比较干净的init.el ...



(setq python-python-commandd:/ bin / python31 / python p>

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



谢谢,



Mike



===开始代码===

 从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,e​​veryone!)

root = Tk()

app = App根)

root.mainloop()


解决方案

我猜附加到tty,Python解释器(通过C stdio)切换到缓冲的缓冲的缓冲区,并且不冲洗stdout直到它关闭。在Inferior Python:运行Shell编译缓冲区中运行 os.isatty(1)返回false,从而增加了这个猜测的重量。

  def say_hi(self):
print(hi there,e​​veryone!)
sys.stdout.flush()

可能会有所作为。


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 with 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.

这篇关于Emacs:下模式python-shell出现“滞后”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 11:44