11import os
2- import sys
32from glob import glob
43from datetime import datetime
54
65import numpy as np
76import pyvista
87import sphinx
9- from sphinx .util import logging
108from ansys .dpf .core import __version__ , server , server_factory
119from ansys .dpf .core .examples import get_example_required_minimum_dpf_version
1210from 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
333331def 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-
382352def setup (app : sphinx .application .Sphinx ) -> None :
383353 """
384354 Run hook function(s) during the documentation build.
0 commit comments