Emacs/Python: running python-shell in line buffered vs. block buffered mode
Asked Answered
F

1

5

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.

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.

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

Thanks,

Mike

Fuze answered 21/5, 2010 at 10:41 Comment(0)
F
4

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

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

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

(setenv "PYTHONUNBUFFERED" "x")
Fuze answered 21/5, 2010 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.