-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-101607 causes regression in third-party psutil package on macOS #102493
Comments
@giampaolo FYI |
Hi @ned-deily. That indeed looks like a psutil bug because EPERM should be translated into AccessDenied. What psutil version is this? |
I see it with current HEAD of cpython main branch and either the most recent PyPI psutil release or current HEAD of the psutil GitHub repo. |
Is the behavior changed by #101607 keeping the version of psutil constant? |
In psutil, error originates from: |
Yes. see #101578 |
The implementation of |
I think this is the fix: diff --git a/Python/errors.c b/Python/errors.c
index f573bed3d6..e62c6e5e71 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -208,7 +208,7 @@ _PyErr_SetObject(PyThreadState *tstate, PyObject *exception, PyObject *value)
}
if (value != NULL && PyExceptionInstance_Check(value))
tb = PyException_GetTraceback(value);
- _PyErr_Restore(tstate, Py_XNewRef(exception), value, tb);
+ _PyErr_Restore(tstate, Py_NewRef(Py_TYPE(value)), value, tb);
} We're now normalising twice - once in SetObejct and then again in PyErr_Restore. |
And I think we also need to check subclass rather than equality when normalising. - if (value == NULL || (PyObject *)Py_TYPE(value) != exception) {
+ int is_subclass = 0;
+ if (value != NULL) {
+ is_subclass = PyObject_IsSubclass((PyObject*)Py_TYPE(value), exception);
+ if (is_subclass < 0) {
+ return;
+ }
+ }
+ if (value == NULL || !is_subclass) {
|
Co-authored-by: Jelle Zijlstra <[email protected]>
* main: pythongh-102493: fix normalization in PyErr_SetObject (python#102502) pythongh-87092: compiler's CFG construction moved to after codegen stage (python#102320) pythongh-95913: Consolidate build requirements changes in 3.11 WhatsNew (pythonGH-98781) Remove redundant `_ensure_future` in favor of `ensure_future` in `asyncio` (python#102398) pythongh-95913: Edit Faster CPython section in 3.11 WhatsNew (pythonGH-98429) pythongh-90110: Fix the c-analyzer Tool (python#102483) pythongh-101759: Update macOS installer SQLite 3.40.1 checksum (pythongh-102485) Remove unused import of `warnings` from `unittest.loader` (python#102479) Add gettext support to tools/extensions/c_annotations.py (python#101989)
* main: pythongh-102493: fix normalization in PyErr_SetObject (python#102502) pythongh-87092: compiler's CFG construction moved to after codegen stage (python#102320) pythongh-95913: Consolidate build requirements changes in 3.11 WhatsNew (pythonGH-98781) Remove redundant `_ensure_future` in favor of `ensure_future` in `asyncio` (python#102398) pythongh-95913: Edit Faster CPython section in 3.11 WhatsNew (pythonGH-98429) pythongh-90110: Fix the c-analyzer Tool (python#102483) pythongh-101759: Update macOS installer SQLite 3.40.1 checksum (pythongh-102485) Remove unused import of `warnings` from `unittest.loader` (python#102479) Add gettext support to tools/extensions/c_annotations.py (python#101989)
As part of the cPython release process for macOS installers, besides the standard cPython test suite, we run a small set of additional smoke tests. One of these involves an install from source of the psutil package which includes the building of a C extension module. In the run up to the 3.12.0a6 release, we found that our long-unchanged simple test was now failing, a regression from 3.12.0a5 and 3.11.x. The commit causing the failure was bisected to feec49c from GH-101607, a part of issue #101578. From a cursory glance at the traceback and the psutil code, it appears that psutil uses a decorator to translate certain OSError exceptions from its C module into other Python exceptions that its calling code is prepared to handle or ignore. For some reason, that exception translation is now failing. FWIW, this is the first failure of this psutil smoke test in recent memory including previous 3.12.0 alphas. Also, FWIW, this same smoke test does not fail on a reasonably recent Debian Linux system but, of course, that exercises a different platform-dependent code path in psutil.
Because of its dependencies, it is a bit complicated to build and reproduce without changes. Here is one way to do it; it is likely not optimal. This assumes a fairly recent macOS system with Homebrew installed (as described in the devguide) and assumes git checkouts of the cpython and psutil Github repos.
The expected result should be something like:
With the failing commit applied (up to and including the current head of the main branch):
git checkout feec49c40736fc05626a183a8d14c4ebbea5ae28 # failing commit
and repeating the above build and test, the result is now something like:
Note this seems to come from trying to inspect a privileged process and the point of the exception wrapping is to effectively ignore such errors.
Flagging as a potential release-blocker for @Yhg1s
Linked PRs
The text was updated successfully, but these errors were encountered: