WhyNotHugo / sphinx-autorun

Sphinx extension to execute the code output it into a document.
https://pypi.python.org/pypi/sphinx-autorun
BSD 2-Clause "Simplified" License
15 stars 3 forks source link

Eliminate the line buffering error #19

Open petercorke opened 4 years ago

petercorke commented 4 years ago

With python 3.8 and unicode output mode

autorun_languages = {}
autorun_languages['pycon_output_encoding'] = 'UTF-8'

I get lots of error messages like

...opt/miniconda3/envs/dev/lib/python3.8/subprocess.py:838: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
  self.stdin = io.open(p2cwrite, 'wb', bufsize)

This is a simple fix, that maintains back compatibility with the default ASCII mode.

yongrenjie commented 3 years ago

On Python 3.9.2 (macOS Big Sur) I find that bufsize=1 for the default ASCII mode still leads to a bunch of warnings:

/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/subprocess.py:946: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used
  self.stderr = io.open(errread, 'rb', bufsize)

On the other hand, bufsize=-1 (the default value, which "means the system default of io.DEFAULT_BUFFER_SIZE will be used") works without any warnings. The warning message above suggests that this is happening behind the scenes anyway.

I tested bufsize=-1 with UTF-8 input and output and it Works For Me, so it seems that just removing the bufsize keyword argument suffices, at least on my system!