Skip to content

Commit 2373a6f

Browse files
committed
fix: modified function checking server closure after sphinx gallery execution
1 parent bbe1c69 commit 2373a6f

File tree

2 files changed

+6
-37
lines changed

2 files changed

+6
-37
lines changed

doc/source/conf.py

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import os
2-
import sys
32
from glob import glob
43
from datetime import datetime
54

65
import numpy as np
76
import pyvista
87
import sphinx
9-
from sphinx.util import logging
108
from ansys.dpf.core import __version__, server, server_factory
119
from ansys.dpf.core.examples import get_example_required_minimum_dpf_version
1210
from ansys_sphinx_theme import ansys_favicon, get_version_match, pyansys_logo_light_mode, pyansys_logo_dark_mode
@@ -331,37 +329,15 @@ def reset_servers(gallery_conf, fname, when):
331329

332330

333331
def close_live_servers_and_processes(app: sphinx.application.Sphinx) -> None:
334-
from ansys.dpf.core import server, _server_instances
335-
import copy
332+
# Adapted from reset_servers() function, so this can be called after
333+
# sphinx gallery finishes execution
336334
import psutil
335+
from ansys.dpf.core import server
337336
import gc
338337

339-
gc.collect
340-
341-
# Server instances are different from processes.
342-
# Ideally no running servers => no running processes
343-
# Server instances should be closed first
344-
running_servers = sum([1 if instance().live else 0 for instance in _server_instances])
345-
if running_servers:
346-
print(f"{running_servers} live dpf servers found")
347-
print("Closing servers")
348-
349-
copy_instances = copy.deepcopy(_server_instances)
350-
for instance in copy_instances:
351-
try:
352-
instance_object = instance()
353-
if hasattr(instance_object, "shutdown"):
354-
instance_object.shutdown()
355-
except Exception as e:
356-
print(e.args)
357-
pass
358-
server.shutdown_global_server()
359-
running_servers = sum([1 if instance().live else 0 for instance in _server_instances])
360-
print(f"Found {running_servers} live dpf servers after closing")
361-
else:
362-
print("No live dpf servers found")
363-
364-
# Subsequently check running processes and close
338+
gc.collect()
339+
server.shutdown_all_session_servers()
340+
365341
proc_name = "Ans.Dpf.Grpc"
366342
nb_procs = 0
367343
for proc in psutil.process_iter():
@@ -373,12 +349,6 @@ def close_live_servers_and_processes(app: sphinx.application.Sphinx) -> None:
373349
except psutil.NoSuchProcess:
374350
pass
375351

376-
# Check if processes were actually killed
377-
if nb_procs:
378-
print(f"Killed {nb_procs} {proc_name} processes.")
379-
else:
380-
print(f"No processes were found running")
381-
382352
def setup(app: sphinx.application.Sphinx) -> None:
383353
"""
384354
Run hook function(s) during the documentation build.

requirements/requirements_docs.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ 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)