ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
423 stars 120 forks source link

How to close all APDL tasks #1692

Closed germa89 closed 1 year ago

germa89 commented 1 year ago

In Windows, exiting might leave some orphan processes.

This should not happen.

Discussed in https://github.com/pyansys/pymapdl/discussions/1687

Originally posted by **natter1** December 13, 2022 I have a script that runs pymapdl repeatedly. Sometimes one of the simulations causes an error. I try to catch that and make sure to close the mapdl-task. ``` a.mapdl.exit() time.sleep(wait_s) ``` Often this is enough, but sometimes an MAPDL-task keeps running (I still don't know what exactly is responsibl for this). This prevents the next simulation to start ("unable to remove lock-file"). Is there a way to force a shutdown of all running MAPDL-tasks via python?
germa89 commented 1 year ago

Proposed approach: https://stackoverflow.com/questions/1230669/subprocess-deleting-child-processes-in-windows

natter1 commented 1 year ago

As a sidenote - I'm actually able to close the running process, if I add mapdl._exited = False before a.mapdl.exit()

germa89 commented 1 year ago

What was the value before issuing mapdl._exited = False ??

natter1 commented 1 year ago

True I still have to check, if this was done by PyMAPDL itself (I think so), or if I called exit() somewhere myself outside my error-handling.

germa89 commented 1 year ago

Could you share you script so I can debug better?