Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Emacs/Python:以行缓冲模式与块缓冲模式运行pythonshell_Python_Emacs_Output Buffering - Fatal编程技术网

Emacs/Python:以行缓冲模式与块缓冲模式运行pythonshell

Emacs/Python:以行缓冲模式与块缓冲模式运行pythonshell,python,emacs,output-buffering,Python,Emacs,Output Buffering,在一个相关的问答中,有人假设emacs(23.2)中的python shell是块缓冲的,而不是行缓冲的。建议的修复方法是将sys.stdout.flush()添加到脚本中我希望stdio将其内容刷新到python shell的位置 有没有办法欺骗PythonShell(在Windows上运行emacs 23.2,而不是Linux)使其a)认为它连接到TTY,或者b)使用行缓冲而不是块缓冲模式?我不明白为什么我可以在空闲状态下这样做,但不能在emacs中这样做 我宁愿自定义emacs,也不愿在脚

在一个相关的问答中,有人假设emacs(23.2)中的python shell是块缓冲的,而不是行缓冲的。建议的修复方法是将sys.stdout.flush()添加到脚本中我希望stdio将其内容刷新到python shell的位置

有没有办法欺骗PythonShell(在Windows上运行emacs 23.2,而不是Linux)使其a)认为它连接到TTY,或者b)使用行缓冲而不是块缓冲模式?我不明白为什么我可以在空闲状态下这样做,但不能在emacs中这样做

我宁愿自定义emacs,也不愿在脚本中添加sys.stdout.flush()。叫我懒惰:-)

谢谢


Mike

对于那些想知道的人,我认为相关的行为在emacs“7.子进程\7.3 shell和子进程中的缓冲”中进行了讨论

在shell缓冲区中,stdout是一个管道句柄,因此在块中进行缓冲。如果希望程序的缓冲行为表现不同,则必须更改程序本身;您可以使用setbuf和setvbuf来处理缓冲语义

通过将以下内容添加到my init.el中解决(有关更多详细信息,请参阅此SO链接):

(setenv "PYTHONUNBUFFERED" "x")