homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: subprocess.Popen with universal_newlines and nonblocking streams fails with "can't concat NoneType to bytes"
Type: behavior Stage: resolved
Components: IO Versions: Python 3.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: The io module doesn't support non-blocking files
View: 13322
Assigned To: Nosy List: martin.panter, sambayer, vstinner
Priority: normal Keywords:

Created on 2019年01月17日 15:22 by sambayer, last changed 2022年04月11日 14:59 by admin. This issue is now closed.

Messages (3)
msg333883 - (view) Author: Samuel Bayer (sambayer) Date: 2019年01月17日 15:22
This bug is probably related to issue 24560.
This:
>>> import subprocess, fcntl, os
>>>> p = subprocess.Popen(["python", "-c", 'import time; time.sleep(5)'], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, universal_newlines= True)
>>> fcntl.fcntl(p.stderr.fileno(), fcntl.F_SETFL, os.O_NONBLOCK | fcntl.fcntl(p.stderr.fileno(), fcntl.F_GETFL))
>>> p.stderr.read()
causes this:
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/codecs.py", line 321, in decode
 data = self.buffer + input
TypeError: can't concat NoneType to bytes
I'm assuming the problem is that the underlying unbuffered stream returns None and the incremental byte decoder that's induced by universal_newlines = True isn't expecting it.
msg334045 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2019年01月19日 07:42
Yes, universal newlines mode uses the TextIOWrapper class to read the pipe, which isn’t really designed for non-blocking mode. This is the same problem described by Izbyshev at <https://bugs.python.org/issue13322#msg307763>.
Raising TypeError isn’t ideal. IMO it would be better to raise BlockingIOError, which is what basic calls like "os.read" would do, and what "BufferedReader.read" is supposed to do according to the documentation. (However the documentation and implementation don’t match; that is what Issue 13322 is about.)
msg354336 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019年10月10日 08:26
I close this issue as a duplicate of bpo-13322 which is older and has a longer history.
History
Date User Action Args
2022年04月11日 14:59:10adminsetgithub: 79943
2019年10月10日 08:26:26vstinnersetstatus: open -> closed

superseder: The io module doesn't support non-blocking files

nosy: + vstinner
messages: + msg354336
resolution: duplicate
stage: resolved
2019年03月15日 08:20:42martin.panterlinkissue36293 superseder
2019年01月19日 07:42:50martin.pantersettype: crash -> behavior

messages: + msg334045
nosy: + martin.panter
2019年01月18日 11:16:17nanjekyejoannahsettitle: subprocess.Popen with universal_newlines and nonblocking streams failes with "can't concat NoneType to bytes" -> subprocess.Popen with universal_newlines and nonblocking streams fails with "can't concat NoneType to bytes"
2019年01月17日 15:22:48sambayercreate

AltStyle によって変換されたページ (->オリジナル) /