Getting "MapdlConnectionError" often when runnung PyMAPDL

Hi Team,
We have developed a PyMAPDL script. When we run the script we get frequently the following error:

Error using mapdl_grpc>_multi_connect
Python Error: MapdlConnectionError: Unable to connect to MAPDL gRPC instance at
Reached either maximum amount of connection attempts (5) or timeout (45 s).The MAPDL process seems to be alive (PID: 24408) but PyMAPDL cannot connect to

Error in mapdl_grpc>init (line 387)

Error in mapdl_grpc>init (line 395)

Error in launcher>launch_mapdl (line 1972)

Error in launcher>launch_mapdl (line 1993)

Error in ModalSensitivity>launch_mapdl (line 275)

Error in ModalSensitivity>perform_modal_sensitivity (line 78)

Then if we run the script again it runs smoothly without any issues. This error we get often like appx. once every 3-4 runs.

Here, we are running the developed PyMAPDL script through the MATLAB environment.
Please suggest why this error raises and how to resolve the issue.