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
RecursionError after exception in the psutil.Popen.__init__() #1121
Comments
How can I reproduce this? |
from raven.base import DummyClient
import psutil
client = DummyClient()
client.is_enabled = lambda: True
try:
proc = psutil.Popen('program_not_found')
except Exception as e:
client.captureException() |
Can't reproduce it. I get:
|
I uses Python 3.6. Maybe the error only appears in Python 3. |
I can't reproduce it. Please show me the full traceback. Actually can you do that (reproduce the issue) from the interactive python shell itself and paste the output? |
There's something weird. Before RecursionError I see
Do you get an error like that? |
The whole point is in using |
So it does not occur if you remove |
Traceback is not truncated - it ends with RecursionError, because |
Yes, RecursionError does not occur if used default Python |
If you define |
Lines 441 to 454 in fe0799f
|
OK, good. What traceback do you get by defining |
https://gist.github.com/Cykooz/72ffb05e65112c06ea9b7e718d0d387f As you can see, in this case python-shell did not fall and did not exit to the console. |
Mmmm... probably better but still incorrect as the right exception should be |
Exception |
This is not bug of Your code expects that a |
I don't understand how can raven call |
In Python, instance is created by You can see
|
Ok, you may fix it by other way - by correct of getting def __getattribute__(self, name):
try:
return object.__getattribute__(self, name)
except AttributeError:
try:
subproc = object.__getattribute__(self, '__subproc')
return object.__getattribute__(subproc, name)
except AttributeError:
raise AttributeError("%s instance has no attribute '%s'"
% (self.__class__.__name__, name)) |
Or you may use def __getattr__(self, name):
subproc = object.__getattribute__(self, '__subproc')
return getattr(subproc, name) |
Using access to the attributes of an instance through a dot (like |
Small fix for my last code example: def __getattr__(self, name):
subproc = object.__getattribute__(self, '_Popen__subproc')
return getattr(subproc, name) An identifier of class-private member is textually replaced with |
Look at this code from constructor of psutil.Popen:
psutil/psutil/__init__.py
Line 1384 in fe0799f
If it raises exception, then
self.__subproc
will be absent in the instance ofpsutil.Popen
. In this case follow code will causes an exceptionRecursionError
.psutil/psutil/__init__.py
Line 1416 in fe0799f
This bug can be fixed very simple - you will need to add a default value of __subproc at class level:
The text was updated successfully, but these errors were encountered: