- http://www.mathworks.com/matlabcentral/fileexchange/32005-cmdwintool
- http://www.mathworks.com/matlabcentral/fileexchange/31272-datahash
- http://www.mathworks.com/matlabcentral/fileexchange/24871-autowarndlg
Default Timeout after inactivity
21 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
As part of the university, we are using network licenses from the university-wide license server. Matlab (central installation on a mounted network disk) is run by our users (~100) on a couple of (around 20) networked unix computers. While the licenses are returned automatically when users are inactive for a couple of time, the (Matlab-) programs itself are still running consuming memory and other system resources.
We're looking for an option to exit Matlab after a time of inactivity to 'clean up' our systems from unwanted resources usage. Since all users execute a matlab program of the same installation it would be optimal to be able to select a default value (e.g. 2 hrs) which could be overwritten by users individually.
Looking through Matlab preferences and help as well as through the support FAQ & questions I didn't found such an option. Did I overlook something? Otherwise this would be a feature that seems to be really helpful in coping with our limited resources but which is still missing ...
Regards, Roger
0 comentarios
Respuestas (4)
Jan
el 14 de Oct. de 2013
Editada: Jan
el 14 de Oct. de 2013
It is unclear what "inactivity" exactly means, when the "Matlab-programs" are still running. Do you mean the Matlab application or does Matlab run any user-defined code?
In both cases it might be brute to kill the process after a fixed period of time. But if brute methods are ok, you couldlog the users off from the terminal server after a certain delay. This would free even more resources.
A more or less dirty trick would be a timer, which obtains the contents of the command window every 5 minute and stores its fingerprint. When it did not change for 2 hours, exit the Matlab session - after showing a dialog to warn the user. To my surprise this can be achieved using 3 functions from the FEX written by the same author (shameless self-advertisment):
function QuitOnIdle
UD.Time = now;
UD.Hash = '';
T = timer('ExecutionMode', 'fixedSpacing', ...
'BusyMode', 'drop', ...
'ObjectVisibility', 'off', ... % Hide timer handle
'Period', 300, ... % 5 minutes
'TimerFcn', @checkActivity, ...
'UserData', UD, ...
'Tag', 'QuitOnIdle_Timer'); % If somebody is wondering
start(T);
function checkActivity(TimerH, EventData)
UD = get(TimerH, 'UserData');
CmdText = CmdWinTool('getText');
newHash = DataHash(CmdText);
if ~isequal(newHash, UD.Hash)
UD.Now = now;
UD.Hash = newHash;
set(TimerH, 'UserData', UD);
elseif etime(now, UD.Now) > 2 * 3600 % 2 hours without a change
Opt.Delay = 120; % Wait 2 minutes
Opt.Button = {'Shut down', 'Keep running'}; % 1st is default
Opt.Interpreter = 'tex';
Opt.Wrap = true;
[Reply, TimeOut] = AutoWarnDlg( ...
{'This Matlab session is shut down automatically after 2 hours of idle.'}, ...
'You have a chance to keep this session running.'}, ...
'Auto Shutdown', Opt);
if strcmp(Reply, 'Shut down')
try
% New Matlab versions allow to save open files in the editor programatically!
% But this should be included in TRY CATCH, because older versions do not know this.
% Close open figures:
try
close('all', 'hidden'); % close all figures
catch % DeleteFcn crashed?
Figs = findobj(allchild(0), 'flat', 'type', 'figure');
set(Figs, 'DeleteFcn', '', 'HandleVisibility', 'on');
close('all'); % close all figures
end
% Close all open files:
fclose('all');
% Save the current workspace to a MAT file in the user folder?
folder = strtok(userpath, pathsep); % First userpath folder only
file = fullfile(folder, sprintf('AutoSave_%s.mat', datestr(now, 0)));
evalin('base', ['save(''', file, ''')]);
catch
end
% Delete this timer?!
% Goodbye:
quit('force');
else
UD.Now = now; % Start a new period
set(TimerH, 'UserData', UD);
end
end
Now add a call to this function inside startup.m, or if this is user-defined add it with admin privileges in matlabrc.m.
Test this exhaustively! This has been written from scratch in the forum's editor, so neither MLint nor runtime checks have been applied!
It kills Matlab sessions and the users will be very angry if they loose any data. Let all users sign on paper (not any checkbox dialog, which is ignored by all adult computer users), that they know and accept this restriction. Check what happens, if teh system clock is reset at the change of the daylight saving time or if the user resets the clock. And again:
Killing sessions is potentially evil! Do not blame me in case of troubles.
[EDITED] I forgot to mention a thrilling method to catch the user's attention: Let the machine beep massively before the closing dialog appears.
See also for saving currently used data and files:
0 comentarios
Andreas Goser
el 14 de Oct. de 2013
It seems to me the root cause is that end users do not care about correctly closing those sessions. And I would assume that those users not necessarily have set up smart ways of saving their data and that killing such a session would probably have impact on their work. So even if the behaviour of those users is to blame, I would not recommend killing sessions (Note that I see also Jan saying this in a similar way).
Saying that, I would not address this technically... I am sure you can somehow identify the users' login name / email address and send them kind emails where you describe the impact of what they are doing.
1 comentario
Jan
el 14 de Oct. de 2013
My suggested function could be used to send a message to the admin containing the user and computer name instead of the killing.
I hesitate to elaborate the Auto-Killer and publish it in the FEX. But if I do so, the default behavior will be an annoying warning dialog only asking the user to shutdown manually.
2000rogers
el 14 de Oct. de 2013
4 comentarios
Jan
el 14 de Oct. de 2013
@2000rogers: But you find such a simple mechanism implemented in Matlab on this page. It requires a few lines of code only, but has a high risk of deleting data. This is a good reason not to ship this in a standard installation.
It is impossible to detect, if the previous command has finished without an error condition, except if you allow a well define set of function for the users only. Even then a core dumping crash will not set the error condition sufficiently. The visibility of the Matlab prompt is a weak condition also: The prompt can be active while a GUI is open, whose UserData contain valuable results.
Melanie Guthrey
el 3 de En. de 2017
Editada: Melanie Guthrey
el 3 de En. de 2017
Hello Roger, I don't know if you are still having this issue, but you can now use FlexNet Manager to set a TIMEOUT for MATLAB. See more info here: https://www.mathworks.com/matlabcentral/answers/98614-can-i-configure-my-license-server-to-return-idle-matlab-seats Good luck!
0 comentarios
Ver también
Categorías
Más información sobre Manage Products en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!