Skip to content

Commit b9a2ec7

Browse files
diningPhilosopher64Prabhakar Kumar
authored andcommitted
Allow Stop MATLAB button when MATLAB is in a starting state.
1 parent 9d3dab3 commit b9a2ec7

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

gui/src/actionCreators/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export function fetchStopMatlab() {
286286
}
287287

288288
dispatch(requestStopMatlab());
289-
const response = await fetchWithTimeout(dispatch, './stop_matlab', options, 15000);
289+
const response = await fetchWithTimeout(dispatch, './stop_matlab', options, 30000);
290290
const data = await response.json();
291291
dispatch(receiveStopMatlab(data));
292292

gui/src/components/Controls/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import {
88
selectSubmittingServerStatus,
99
selectLicensingIsMhlm,
1010
selectLicensingProvided,
11-
selectMatlabRunning,
11+
selectMatlabUp,
1212
selectMatlabStarting,
1313
selectMatlabStopping,
14+
selectMatlabDown,
1415
selectMatlabVersion,
1516
selectError,
1617
selectIsAuthenticated,
@@ -36,14 +37,14 @@ function Controls({
3637
const submitting = useSelector(selectSubmittingServerStatus);
3738
const licensed = useSelector(selectLicensingProvided);
3839
const mhlmLicense = useSelector(selectLicensingIsMhlm);
39-
const matlabRunning = useSelector(selectMatlabRunning);
4040
const matlabStarting = useSelector(selectMatlabStarting);
41+
const matlabUp = useSelector(selectMatlabUp);
4142
const matlabStopping = useSelector(selectMatlabStopping);
43+
const matlabDown = useSelector(selectMatlabDown);
4244
const matlabVersion = useSelector(selectMatlabVersion);
4345
const error = useSelector(selectError);
4446
const authEnabled = useSelector(selectAuthEnabled);
4547
const isAuthenticated = useSelector(selectIsAuthenticated);
46-
// const canTerminateIntegration = !submitting;
4748
const canResetLicensing = licensed && !submitting;
4849

4950
const feedbackBody = useMemo(
@@ -57,7 +58,7 @@ MATLAB version: ${matlabVersion}%0D%0A`,
5758
const Confirmations = {
5859
START: {
5960
type: 'confirmation',
60-
message: `Are you sure you want to ${matlabRunning ? 're' : ''}start MATLAB?`,
61+
message: `Are you sure you want to ${ matlabUp ? 're' : ''}start MATLAB?`,
6162
callback: fetchStartMatlab
6263
},
6364
STOP: {
@@ -98,7 +99,7 @@ MATLAB version: ${matlabVersion}%0D%0A`,
9899
<button
99100
id="startMatlab"
100101
data-testid='startMatlabBtn'
101-
className={getBtnClass(matlabRunning ? 'restart' : 'start')}
102+
className={getBtnClass(matlabUp ? 'restart' : 'start')}
102103
onClick={() => callback(Confirmations.START)}
103104
disabled={!licensed || matlabStarting || matlabStopping || (authEnabled && !isAuthenticated)}
104105
data-for="control-button-tooltip"
@@ -112,7 +113,7 @@ MATLAB version: ${matlabVersion}%0D%0A`,
112113
data-testid='stopMatlabBtn'
113114
className={getBtnClass('stop')}
114115
onClick={() => callback(Confirmations.STOP)}
115-
disabled={!matlabRunning || (authEnabled && !isAuthenticated)}
116+
disabled={ matlabStopping || matlabDown || (authEnabled && !isAuthenticated)}
116117
data-for="control-button-tooltip"
117118
data-tip="Stop MATLAB"
118119
>

gui/src/selectors/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ export const selectMatlabUp = createSelector(
4242
matlabStatus => matlabStatus === 'up'
4343
);
4444

45-
export const selectMatlabRunning = createSelector(
46-
selectMatlabStatus,
47-
matlabStatus => matlabStatus === 'up'
48-
);
49-
5045
export const selectMatlabStarting = createSelector(
5146
selectMatlabStatus,
5247
matlabStatus => matlabStatus === 'starting'
@@ -57,6 +52,11 @@ export const selectMatlabStopping = createSelector(
5752
matlabStatus => matlabStatus === 'stopping'
5853
);
5954

55+
export const selectMatlabDown = createSelector(
56+
selectMatlabStatus,
57+
matlabStatus => matlabStatus === 'down'
58+
);
59+
6060
export const selectOverlayHidable = createSelector(
6161
selectMatlabStatus,
6262
selectIsError,

matlab_proxy/app_state.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,10 +910,13 @@ async def stop_matlab(self, force_quit=False):
910910

911911
waiters = []
912912
if matlab is not None:
913-
# Sending a request to embedded connector works sporadically on posix systems.
914-
# So, terminating the process when force_quit is set to True.
915913
if system.is_posix() and matlab.returncode is None:
916-
if force_quit:
914+
# Sending an exit request to the embedded connector takes time.
915+
# When MATLAB is in a "starting" state (implies the Embedded connector is not up)
916+
# OR
917+
# When force_quit is set to True
918+
# directly terminate the MATLAB process instead.
919+
if await self.get_matlab_state() == "starting" or force_quit:
917920
logger.debug("Forcing the MATLAB process to terminate...")
918921
matlab.terminate()
919922
waiters.append(matlab.wait())

0 commit comments

Comments
 (0)