.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\gallery_examples\99-teardown\teardown.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_gallery_examples_99-teardown_teardown.py: .. _ref_teardown: ========================================= Teardown ========================================= This restores the environment after running the examples. Description ----------- Perform the following steps to set up the environment: - Connect to Sherlock - Exit Sherlock - Delete temp files .. GENERATED FROM PYTHON SOURCE LINES 35-42 .. code-block:: Python import shutil from examples.examples_globals import get_temp_dir from ansys.sherlock.core import LOG, launcher .. GENERATED FROM PYTHON SOURCE LINES 43-46 Exit Sherlock ============= Exit the gRPC connection and shut down Sherlock. .. GENERATED FROM PYTHON SOURCE LINES 46-55 .. code-block:: Python LOG.info("Teardown: connect to and exit Sherlock") try: sherlock = launcher.connect(port=9092, timeout=2) sherlock.common.exit(True) LOG.info("Sherlock exited successfully.") except Exception as e: LOG.error(f"Error exiting Sherlock: {e}") .. GENERATED FROM PYTHON SOURCE LINES 56-59 Clean temporary directory ========================= Delete the directory for storing temp files. .. GENERATED FROM PYTHON SOURCE LINES 59-64 .. code-block:: Python try: shutil.rmtree(get_temp_dir(), ignore_errors=True) except Exception as e: LOG.error(f"Error deleting temporary directory: {e}") .. _sphx_glr_download_examples_gallery_examples_99-teardown_teardown.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: teardown.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: teardown.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: teardown.zip `