Skip to content

Commit 24b945b

Browse files
committed
tc
1 parent 42f9ce5 commit 24b945b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

conf.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@
4949
pio.renderers.default = 'sphinx_gallery'
5050

5151

52+
import sphinx_gallery.gen_rst
53+
import multiprocessing
54+
55+
# Save the original function
56+
def isolated_call(func, args, kwargs, result_queue):
57+
try:
58+
result = func(*args, **kwargs)
59+
result_queue.put((True, result))
60+
except Exception as e:
61+
result_queue.put((False, str(e)))
62+
63+
def make_isolated_version(func):
64+
def wrapper(*args, **kwargs):
65+
result_queue = multiprocessing.Queue()
66+
p = multiprocessing.Process(
67+
target=isolated_call,
68+
args=(func, args, kwargs, result_queue)
69+
)
70+
p.start()
71+
p.join()
72+
success, result = result_queue.get()
73+
if success:
74+
return result
75+
else:
76+
raise RuntimeError(f"Error in isolated process: {result}")
77+
return wrapper
78+
79+
# Monkey-patch
80+
sphinx_gallery.gen_rst.generate_file_rst = make_isolated_version(sphinx_gallery.gen_rst.generate_file_rst
81+
5282
try:
5383
import torchvision
5484
except ImportError:

0 commit comments

Comments
 (0)