Emacs / Python:运行python-shell在行缓冲与块缓冲模式 [英] Emacs/Python: running python-shell in line buffered vs. block buffered mode

查看:183
本文介绍了Emacs / Python:运行python-shell在行缓冲与块缓冲模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在相关问题和答案此处 ,有人假设emacs(23.2)中的python-shell是块缓冲的,而不是行缓冲。推荐的修复是将sys.stdout.flush()添加到脚本中,我想要stdio将其内容刷新到python-shell。

In a related question and answer here, someone hypothesized that python-shell within emacs(23.2) was block-buffered instead of line-buffered. The recommended fix was to add sys.stdout.flush() to the spot in my script where I want stdio to flush its contents to the python-shell.

是否有(python-shell)(在Windows上运行在emacs 23.2中,而不是Linux中)a)认为它附加到TTY或者b)使用线缓冲代替块缓冲模式?我不明白为什么我可以在IDLE中执行此操作,但不能使用emacs。

Is there someway to trick python-shell (running in emacs 23.2 on Windows, not Linux) into either a) thinking it's attached to a TTY or b) using line-buffered instead of block-buffered mode? I don't see why I'd be able to do this in IDLE but not emacs.

我宁愿自定义emacs,而不是添加sys.stdout.flush()在我的脚本致电我懒惰: - )。

I'd rather customize emacs than add sys.stdout.flush() throughout my scripts. Call me lazy :-).

谢谢,

Mike

推荐答案

对于那些想知道的人,我认为相关的行为被讨论这里,在emacs7.子进程\\7.3缓冲在shell和子进程。

For those wondering, I think the relevant behavior is discussed here, in emacs "7. Subprocesses\ 7.3 Buffering in shells and subprocesses".

在一个shell缓冲区,stdout是一个管道句柄,所以被缓冲在块中,如果你希望程序的缓冲行为有所不同,程序本身就需要改变;你可以使用setbuf和setvbuf来处理缓冲语义。

"In a shell buffer, stdout is a pipe handle and so is buffered in blocks. If you would like the buffering behavior of your program to behave differently, the program itself is going to have to be changed; you can use setbuf and setvbuf to manipulate the buffering semantics."

通过将以下内容添加到我的init.el中解决(请参阅此SO链接此处):

Solved by adding the following to my init.el (see this SO link here for more detail):

(setenv "PYTHONUNBUFFERED" "x")

这篇关于Emacs / Python:运行python-shell在行缓冲与块缓冲模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆