-
Notifications
You must be signed in to change notification settings - Fork 140
fix(cli): skip processes owned by other users and handle AccessDenied when stopping MAPDL #4281
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
Conversation
… when stopping MAPDL - Add _can_access_process() and use it in stop() to skip processes not owned by the current user or that raise AccessDenied/NoSuchProcess when queried. - Broaden exception handling in stop() to catch psutil.AccessDenied where appropriate. - Make is_ansys_process() resilient to AccessDenied/NoSuchProcess and return False when process info cannot be accessed. - Add unit test (test_pymapdl_stop_permission_handling) and adjust mocks to include username behavior to ensure permission edge-cases are handled without crashing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a critical bug where the pymapdl stop command would crash when encountering processes owned by other users or when access is denied to process information. The fix adds permission checking and proper exception handling to gracefully skip inaccessible processes.
Key changes:
- Added
_can_access_process()helper function to verify process ownership before attempting operations - Enhanced exception handling throughout to catch
psutil.AccessDeniedalongsidepsutil.NoSuchProcess - Made
is_ansys_process()resilient to permission errors by returningFalsewhen process info is inaccessible
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/ansys/mapdl/core/cli/stop.py | Added _can_access_process() function and improved exception handling to skip processes owned by other users |
| src/ansys/mapdl/core/launcher.py | Wrapped is_ansys_process() logic in try-except to handle AccessDenied and NoSuchProcess exceptions |
| tests/test_cli.py | Added comprehensive test for permission handling scenarios and updated mock processes to include username behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is ❌ Your patch status has failed because the patch coverage (75.00%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #4281 +/- ##
==========================================
+ Coverage 91.19% 91.37% +0.18%
==========================================
Files 193 193
Lines 15726 15740 +14
==========================================
+ Hits 14341 14383 +42
+ Misses 1385 1357 -28 🚀 New features to boost your workflow:
|
|
Skipping coverage as there aren't that many lines. @pyansys-ci-bot LGTM. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

Description
current user or that raise AccessDenied/NoSuchProcess when queried.
process info cannot be accessed.
username behavior to ensure permission edge-cases are handled without crashing.
Issue linked
Close #4256
Checklist
draftif it is not ready to be reviewed yet.feat: adding new MAPDL command)