Skip to content

Commit 935dc41

Browse files
krisctlprabhakk-mw
authored andcommitted
Fixes hang when stopping MATLAB from matlab-proxy.
This issue usually only occurs when MATLAB cold starts for the first time through matlab-proxy. In this state, the matlab-proxy process shares a pipe with the MathWorksServiceHost process and waits for ever for that pipe to close. This change closes the shared stderr pipe before waiting for MATLAB to terminate. fixes #44
1 parent ddc879c commit 935dc41

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

matlab_proxy/app_state.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,11 +1427,26 @@ async def stop_matlab(self, force_quit=False):
14271427
else:
14281428
logger.debug("Sending HTTP request to stop the MATLAB process...")
14291429
try:
1430+
import sys
1431+
14301432
# Send HTTP request
14311433
await self.__send_stop_request_to_matlab()
14321434

1435+
# Close the stderr stream to prevent indefinite hanging on it due to a child
1436+
# process inheriting it, fixes https://github.com/mathworks/matlab-proxy/issues/44
1437+
stderr_stream = matlab._transport.get_pipe_transport(
1438+
sys.stderr.fileno()
1439+
)
1440+
if stderr_stream:
1441+
logger.debug(
1442+
"Closing matlab process stderr stream: %s",
1443+
stderr_stream,
1444+
)
1445+
stderr_stream.close()
1446+
14331447
# Wait for matlab to shutdown gracefully
14341448
await matlab.wait()
1449+
14351450
assert (
14361451
matlab.returncode == 0
14371452
), "Failed to gracefully shutdown MATLAB via the embedded connector"

0 commit comments

Comments
 (0)