Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gevent.subprocess communicate suppresses UnicodeDecodeError and returns empty string instead #1510

Closed
koreno opened this issue Jan 14, 2020 · 0 comments
Labels

Comments

@koreno
Copy link

@koreno koreno commented Jan 14, 2020

  • gevent version: 1.4.0
  • Python version: cPython 3.7.5 (default, Dec 18 2019, 12:57:24) \n[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
  • Operating System: CentOS Linux release 7.7.1908 (Core)

Description:

Running gevent.subprocess.Popen.communicate(), where text is expected but fails to decode, results in a traceback from the greenlet that is not propagated to the caller. Instead, the call returns an empty string:

import gevent
import gevent.monkey
gevent.monkey.patch_subprocess()
from gevent import subprocess

out, _ = subprocess.Popen(['printf', r'\xff'], 
       stdin=subprocess.PIPE,
       stdout=subprocess.PIPE, 
      stderr=subprocess.PIPE).communicate()
assert out == b'\xff'

out, _ = subprocess.Popen(['printf', r'\xff'], 
        universal_newlines=True, 
        stdin=subprocess.PIPE, 
        stdout=subprocess.PIPE, 
        stderr=subprocess.PIPE).communicate()
assert out, "Why is there no output?"

the console shows this traceback, which the Hub writes on greenlets that raised unhandled exceptions:

Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run
  File "/usr/local/lib/python3.7/site-packages/gevent/subprocess.py", line 725, in _read
    data = pipe.read()
  File "/usr/local/lib/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: invalid continuation byte
2020-01-14T10:08:13Z <Greenlet at 0x7ff576becdd0: _read> failed with UnicodeDecodeError
@jamadden jamadden added the Type: Bug label Jan 14, 2020
@jamadden jamadden closed this in acc67c3 Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.