Skip to content

Commit

Permalink
docs: added some hooks for troubleshooting the issue
Browse files Browse the repository at this point in the history
  • Loading branch information
moe-ad committed Dec 2, 2024
1 parent 0ed9e80 commit 33c0f11
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
85 changes: 84 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

import numpy as np
import pyvista
import sphinx
from sphinx.util import logging
from ansys.dpf.core import __version__, server, server_factory
from ansys.dpf.core.examples import get_example_required_minimum_dpf_version
from ansys_sphinx_theme import ansys_favicon, get_version_match, pyansys_logo_light_mode, pyansys_logo_dark_mode
Expand Down Expand Up @@ -158,7 +160,7 @@ def reset_servers(gallery_conf, fname, when):
try:
# check whether the process name matches
if proc_name in proc.name():
# proc.kill()
proc.kill()
nb_procs += 1
except psutil.NoSuchProcess:
pass
Expand Down Expand Up @@ -326,3 +328,84 @@ def reset_servers(gallery_conf, fname, when):

# A list of files that should not be packed into the epub file.
epub_exclude_files = ["search.html"]


def check_global_servers_and_close(app: sphinx.application.Sphinx) -> None:
from ansys.dpf.core import server, _server_instances
import copy
import psutil
import gc

gc.collect

# Server instances are different from processes.
# Ideally just closing the servers => no running processes
# Server instances should be closed first
if _server_instances:
print(f"{len(_server_instances)} dpf server instances found running")
print("Closing server instances")

copy_instances = copy.deepcopy(_server_instances)
for instance in copy_instances:
try:
if hasattr(instance(), "shutdown"):
instance().shutdown()
except Exception as e:
print(e.args)
pass
server.shutdown_global_server()
print(f"{len(_server_instances)} dpf server instances found running after closing")
else:
print("no server instances found running")

# Subsequently check running processes and close
proc_name = "Ans.Dpf.Grpc"
nb_procs = 0
for proc in psutil.process_iter():
try:
# check whether the process name matches
if proc_name in proc.name():
proc.kill()
nb_procs += 1
except psutil.NoSuchProcess:
pass
print(f"Counted {nb_procs} {proc_name} processes after attempting to close.")

# def reset_server_after_sphinx_gallery(app: sphinx.application.Sphinx, exception: Exception) -> None:
# """
# Stop running dpf servers before regardless of documentation build sucess.

# Parameters
# ----------
# app : sphinx.application.Sphinx
# Sphinx application instance containing the all the doc build configuration.

# """
# from ansys.dpf.core import server

# logger = logging.getLogger(__name__)

# try:
# server.check_global_servers_and_close()
# except exception:
# if "Extension error" in str(exception):
# server.check_global_servers_and_close()
# logger.warning("An error occurred during sphinx gallery execution")
# raise exception
# else:
# logger.warning("An error outside sphinx gallery execution occurred")
# raise exception


def setup(app: sphinx.application.Sphinx) -> None:
"""
Run hook function(s) during the documentation build.
Parameters
----------
app : sphinx.application.Sphinx
Sphinx application instance containing the all the doc build configuration.
"""

app.connect("builder-inited", check_global_servers_and_close)
app.connect("build-finished", check_global_servers_and_close)
1 change: 1 addition & 0 deletions requirements/requirements_docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ sphinx-reredirects==0.1.3
sphinx_design==0.6.1
sphinxcontrib-napoleon==0.7
vtk==9.3.1
jupyterlab==4.3.1

0 comments on commit 33c0f11

Please sign in to comment.