Skip to content

Commit 32954d1

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

File tree

1 file changed

+6
-34
lines changed

1 file changed

+6
-34
lines changed

doc/source/conf.py

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -331,37 +331,15 @@ def reset_servers(gallery_conf, fname, when):
331331

332332

333333
def close_live_servers_and_processes(app: sphinx.application.Sphinx) -> None:
334-
from ansys.dpf.core import server, _server_instances
335-
import copy
334+
# Adapted from reset_servers() function, so this can be called after
335+
# sphinx gallery finishes execution
336336
import psutil
337+
from ansys.dpf.core import server
337338
import gc
338339

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
340+
gc.collect()
341+
server.shutdown_all_session_servers()
342+
365343
proc_name = "Ans.Dpf.Grpc"
366344
nb_procs = 0
367345
for proc in psutil.process_iter():
@@ -373,12 +351,6 @@ def close_live_servers_and_processes(app: sphinx.application.Sphinx) -> None:
373351
except psutil.NoSuchProcess:
374352
pass
375353

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-
382354
def setup(app: sphinx.application.Sphinx) -> None:
383355
"""
384356
Run hook function(s) during the documentation build.

0 commit comments

Comments
 (0)