@@ -464,18 +464,7 @@ def __init__(
464
464
if not self ._mapdl_on_hpc and self ._mapdl_process :
465
465
self ._create_process_stds_queue ()
466
466
467
- try :
468
- self ._multi_connect (timeout = timeout )
469
- except MapdlConnectionError as err : # pragma: no cover
470
- self ._post_mortem_checks ()
471
- self ._log .debug (
472
- "The error wasn't caught by the post-mortem checks.\n The stdout is printed now:"
473
- )
474
- self ._log .debug (self ._stdout )
475
-
476
- raise err # Raise original error if we couldn't catch it in post-mortem analysis
477
- else :
478
- self ._log .debug ("Connection established" )
467
+ self .reconnect_to_mapdl ()
479
468
480
469
# Avoiding muting when connecting to the session
481
470
# It might trigger some errors later on if not.
@@ -527,6 +516,38 @@ def _before_run(self, _command: str) -> None:
527
516
# For some reason the session hasn't been created
528
517
self ._create_session ()
529
518
519
+ def _connect_to_mapdl (self , timeout : int ):
520
+ """(Re)connect to an existing MAPDL instance"""
521
+ try :
522
+ self ._multi_connect (timeout = timeout )
523
+ except MapdlConnectionError as err : # pragma: no cover
524
+ self ._post_mortem_checks ()
525
+ self ._log .debug (
526
+ "The error wasn't caught by the post-mortem checks.\n The stdout is printed now:"
527
+ )
528
+ self ._log .debug (self ._stdout )
529
+
530
+ raise err # Raise original error if we couldn't catch it in post-mortem analysis
531
+ else :
532
+ self ._log .debug ("Connection established" )
533
+
534
+ def reconnect_to_mapdl (self , timeout : int = None ):
535
+ """Reconnect to an already instantiated MAPDL instance.
536
+
537
+ Re-establish an stopped or crashed gRPC connection with an already alive
538
+ MAPDL instance. This function does not relaunch the MAPDL instance.
539
+
540
+ Parameters
541
+ ----------
542
+ timeout : int, optional
543
+ Timeout before raising an exception, by default None
544
+ """
545
+
546
+ if timeout is None :
547
+ timeout = self ._timeout
548
+
549
+ self ._connect_to_mapdl (timeout )
550
+
530
551
def _create_process_stds_queue (self , process = None ):
531
552
from ansys .mapdl .core .launcher import (
532
553
_create_queue_for_std , # Avoid circular import error
0 commit comments