@@ -193,6 +193,13 @@ class App:
193193 feature_flags : list, optional
194194 List of feature flag names to enable. Default is [].
195195 Available flags include: 'ThermalShells', 'MultistageHarmonic', 'CPython'.
196+ reuse_instance : bool, optional
197+ When ``True``, gallery instance sharing is skipped for this constructor,
198+ so initialization follows the same path as when the module-level
199+ ``BUILDING_GALLERY`` flag is ``False``. Use this to opt out of gallery
200+ sharing without assigning ``pymechanical.BUILDING_GALLERY = False`` (for
201+ example when the flag is set globally for documentation builds).
202+ Default is ``False``.
196203
197204 Examples
198205 --------
@@ -236,12 +243,16 @@ def __init__(
236243 self ,
237244 db_file : str | None = None ,
238245 private_appdata : bool = False ,
246+ * ,
247+ reuse_instance : bool = False ,
239248 ** kwargs : typing .Any ,
240249 ) -> None :
241250 """Construct an instance of the mechanical Application."""
242251 global INSTANCES
243252 from ansys .mechanical .core import BUILDING_GALLERY
244253
254+ use_gallery_sharing = BUILDING_GALLERY and not reuse_instance
255+
245256 self ._enable_logging = kwargs .get ("enable_logging" , True )
246257 if self ._enable_logging :
247258 self ._log = LOG
@@ -270,7 +281,7 @@ def __init__(
270281
271282 # If the building gallery flag is set, we need to share the instance
272283 # This can apply to running the `make -C doc html` command
273- if BUILDING_GALLERY :
284+ if use_gallery_sharing :
274285 if len (INSTANCES ) != 0 :
275286 # Get the first instance of the app
276287 instance : App = INSTANCES [0 ]
@@ -668,7 +679,8 @@ def _share(self, other) -> None:
668679 """Shares the state of self with other.
669680
670681 Other is another instance of App.
671- This is used when the BUILDING_GALLERY flag is on.
682+ This is used when the BUILDING_GALLERY flag is on and the constructor
683+ was not called with ``reuse_instance=True``.
672684 In that mode, multiple instance of App are used, but
673685 they all point to the same underlying application
674686 object. Because of that, special care needs to be
0 commit comments