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

AttributeError: __exit__ when creating subprocess in sample python code #37

Open
mylogon341 opened this issue Nov 30, 2019 · 2 comments
Labels
notice wontfix This will not be worked on

Comments

@mylogon341
Copy link

Hi. I'm very new to python (currently a lead ios dev) and have little experience in debugging (beyond google). I am trying to run the rgb-to-gif.py script on a pi zero w (headless). Building, earlier on, i used the make I2C_MODE=RPI method. I believe it is using python2.7 by default.
When I try to run it, I just end up hitting this error, which i'm having trouble finding help with elsewhere on the ole' internet.
I've literally changed nothing in the code, and it looks like I successfully built the rawrgb correctly. But if no one else is having this issue, I would suggest i've skimmed over an important detail somewhere 🤔

Traceback (most recent call last):
  File "rgb-to-gif.py", line 43, in <module>
    with subprocess.Popen(["sudo", RAW_RGB_PATH, "{}".format(fps)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) as camera:
AttributeError: __exit__

Thanks

@strangerman
Copy link

I'm having the same issue. Were you able to find a solution for this?

@Gadgetoid
Copy link
Member

Gadgetoid commented Mar 10, 2020

This is an obtuse error and no mistake. Python classes are supposed to define __enter__ and __exit__ methods which allow for with X as Y: to work. __enter__ is called at the start of the with, and __exit__ is called when it goes out of scope.

It's possible that in Python 2.x these attributes aren't defined on subprocess.Popen. In fact this very bug is described here: https://bugs.python.org/issue13202

Looks like context management support (the __enter__ and __exit__ methods) was not added to subprocess.Popen until Python 3.2.

Solution: make sure you're running with Python 3, which is the default language this should be built against, the the default interpreter when you run the file as ./rgb-to-gif.py without explicitly specifying python.

Since Python 2.x is now end of life I'll tag this as a notice to anyone running into the same issue.

@Gadgetoid Gadgetoid added notice wontfix This will not be worked on labels Mar 10, 2020
@Gadgetoid Gadgetoid reopened this Jan 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notice wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants