-
Notifications
You must be signed in to change notification settings - Fork 140
refactor: list_instances #4329
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
Merged
Merged
refactor: list_instances #4329
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…d instance retrieval
…instance retrieval
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4329 +/- ##
==========================================
- Coverage 91.41% 91.38% -0.03%
==========================================
Files 193 194 +1
Lines 15745 15783 +38
==========================================
+ Hits 14393 14424 +31
- Misses 1352 1359 +7 🚀 New features to boost your workflow:
|
…mapdl into refactor/list_instances
Collaborator
Author
|
@pyansys-ci-bot LGTM. |
pyansys-ci-bot
approved these changes
Nov 28, 2025
Contributor
pyansys-ci-bot
left a comment
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Description
refactor list instances CLI. Also improved the speed, down to 1.5s to execute.
Issue linked
NA
Checklist
draftif it is not ready to be reviewed yet.feat: adding new MAPDL command)AI Summary
Optimize CLI list command performance with process enumeration improvements
Summary
This PR optimizes the CLI
listcommand performance by improving process enumeration efficiency, reducing execution time by 52%.Changes Made
Core CLI Module (
src/ansys/mapdl/core/cli/core.py):get_mapdl_instances()to usepsutil.process_iter(attrs=['name'])instead ofpsutil.process_iter()proc.name()toproc.info['name']to leverage pre-fetched process attributesTest Updates (
tests/test_cli.py):.infoattribute for compatibility with optimized process iterationmake_fake_process(),make_other_user_process(),make_inaccessible_process(), and standalone mocksLazy Imports (
src/ansys/mapdl/core/__init__.py):Performance Metrics
pymapdl listpymapdl listGoals and Ideas
The primary goal was to address slow CLI startup times, particularly for the
listcommand which enumerates all system processes to find MAPDL instances. The bottleneck was identified as the process iteration loop making individual system calls for each process name.The optimization leverages psutil's
attrsparameter to fetch process names upfront during iteration, eliminating redundant system calls. This approach maintains full compatibility while significantly improving performance.Additional lazy loading of heavy modules further reduces CLI startup overhead, contributing to the overall performance improvement.
Testing
This optimization makes the CLI more responsive for users working with MAPDL instances, especially in environments with many running processes.