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: AttributeError in Popen.communicate()
Type: behavior Stage:
Components: Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Luke Campagnola
Priority: normal Keywords:

Created on 2017-04-29 08:21 by Luke Campagnola, last changed 2022-04-11 14:58 by admin.

Messages (2)
msg292575 - (view) Author: Luke Campagnola (Luke Campagnola) Date: 2017-04-29 08:21
In my application, calling communicate() on a Popen instance is giving the following exception:

  . . .
  File "/usr/lib/python3.5/subprocess.py", line 1072, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/usr/lib/python3.5/subprocess.py", line 1693, in _communicate
    stdout = self._fileobj2output[self.stdout]
AttributeError: 'Popen' object has no attribute '_fileobj2output'


I have not been able to reproduce this in a simple example, but I imagine this could happen if Popen._communicate() raises an exception in the first 20 lines or so--this would cause _communication_started to be set True, even though _fileobj2output has not been initialized.

I suggest setting self._fileobj2output = None in Popen.__init__() and changing the relevant code in _communicate() from 

            if not self._communication_started:
                self._fileobj2output = {}

to: 

            if self._fileobj2output is None:
                self._fileobj2output = {}
msg292577 - (view) Author: Luke Campagnola (Luke Campagnola) Date: 2017-04-29 08:24
Update:  this appears to be the prior exception that causes _communication_started and _fileobj2ouput to be out of sync:

  File "/usr/lib/python3.5/subprocess.py", line 1072, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/usr/lib/python3.5/subprocess.py", line 1672, in _communicate
    self.stdin.flush()
ValueError: flush of closed file
History
Date User Action Args
2022-04-11 14:58:45adminsetgithub: 74389
2017-04-29 08:24:46Luke Campagnolasetmessages: + msg292577
2017-04-29 08:21:08Luke Campagnolacreate