Skip to content

Commit 33c0f11

Browse files
committed
docs: added some hooks for troubleshooting the issue
1 parent 0ed9e80 commit 33c0f11

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

doc/source/conf.py

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import numpy as np
77
import pyvista
8+
import sphinx
9+
from sphinx.util import logging
810
from ansys.dpf.core import __version__, server, server_factory
911
from ansys.dpf.core.examples import get_example_required_minimum_dpf_version
1012
from ansys_sphinx_theme import ansys_favicon, get_version_match, pyansys_logo_light_mode, pyansys_logo_dark_mode
@@ -158,7 +160,7 @@ def reset_servers(gallery_conf, fname, when):
158160
try:
159161
# check whether the process name matches
160162
if proc_name in proc.name():
161-
# proc.kill()
163+
proc.kill()
162164
nb_procs += 1
163165
except psutil.NoSuchProcess:
164166
pass
@@ -326,3 +328,84 @@ def reset_servers(gallery_conf, fname, when):
326328

327329
# A list of files that should not be packed into the epub file.
328330
epub_exclude_files = ["search.html"]
331+
332+
333+
def check_global_servers_and_close(app: sphinx.application.Sphinx) -> None:
334+
from ansys.dpf.core import server, _server_instances
335+
import copy
336+
import psutil
337+
import gc
338+
339+
gc.collect
340+
341+
# Server instances are different from processes.
342+
# Ideally just closing the servers => no running processes
343+
# Server instances should be closed first
344+
if _server_instances:
345+
print(f"{len(_server_instances)} dpf server instances found running")
346+
print("Closing server instances")
347+
348+
copy_instances = copy.deepcopy(_server_instances)
349+
for instance in copy_instances:
350+
try:
351+
if hasattr(instance(), "shutdown"):
352+
instance().shutdown()
353+
except Exception as e:
354+
print(e.args)
355+
pass
356+
server.shutdown_global_server()
357+
print(f"{len(_server_instances)} dpf server instances found running after closing")
358+
else:
359+
print("no server instances found running")
360+
361+
# Subsequently check running processes and close
362+
proc_name = "Ans.Dpf.Grpc"
363+
nb_procs = 0
364+
for proc in psutil.process_iter():
365+
try:
366+
# check whether the process name matches
367+
if proc_name in proc.name():
368+
proc.kill()
369+
nb_procs += 1
370+
except psutil.NoSuchProcess:
371+
pass
372+
print(f"Counted {nb_procs} {proc_name} processes after attempting to close.")
373+
374+
# def reset_server_after_sphinx_gallery(app: sphinx.application.Sphinx, exception: Exception) -> None:
375+
# """
376+
# Stop running dpf servers before regardless of documentation build sucess.
377+
378+
# Parameters
379+
# ----------
380+
# app : sphinx.application.Sphinx
381+
# Sphinx application instance containing the all the doc build configuration.
382+
383+
# """
384+
# from ansys.dpf.core import server
385+
386+
# logger = logging.getLogger(__name__)
387+
388+
# try:
389+
# server.check_global_servers_and_close()
390+
# except exception:
391+
# if "Extension error" in str(exception):
392+
# server.check_global_servers_and_close()
393+
# logger.warning("An error occurred during sphinx gallery execution")
394+
# raise exception
395+
# else:
396+
# logger.warning("An error outside sphinx gallery execution occurred")
397+
# raise exception
398+
399+
400+
def setup(app: sphinx.application.Sphinx) -> None:
401+
"""
402+
Run hook function(s) during the documentation build.
403+
404+
Parameters
405+
----------
406+
app : sphinx.application.Sphinx
407+
Sphinx application instance containing the all the doc build configuration.
408+
"""
409+
410+
app.connect("builder-inited", check_global_servers_and_close)
411+
app.connect("build-finished", check_global_servers_and_close)

requirements/requirements_docs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ sphinx-reredirects==0.1.3
1515
sphinx_design==0.6.1
1616
sphinxcontrib-napoleon==0.7
1717
vtk==9.3.1
18+
jupyterlab==4.3.1

0 commit comments

Comments
 (0)