Close script kept in memory

4 views (last 30 days)
Raphaël Leclercq
Raphaël Leclercq on 28 May 2019
Hi everyone,
I have some trouble with a code called from task scheduler every 20 minutes. Each time, I call a master script which call others ones. Each chil script is also calling a script which is renamed during the process.
I used the exit or quit force function in the master script (and exit in the task scheduler). But, script are kept in memory which is quickly a problem due to the frequency of the process.
Did someone meet this problem ? Have you got any suggestions?
Thank you very much for your help, I will appreciate to answer to your comments,
PS : In the attachment, a quick diagram of the architecture.
Schema_architecture.PNG

Answers (3)

Jan
Jan on 28 May 2019
What exactly does "code called from task scheduler" mean? How do you call the Matlab code? How do you define "exit in the task scheduler"? "Each chil script is also calling a script which is renamed during the process" - this sounds like a bad programming style. Creating code dynamically has some disadvantages. It is cleaner to keep the code fixed and trigger modifications by providing different inputs. I would not even use a Matlab script for productive work, but I work with functions in general.
I do not know, what causes the observed effect. But I'm scared if I see scripts in different "levels", which are renamed dynamically.
Why do you assume, that the script is kept in memory? It looks like the Matlab instance is not closed. Is there any reason to start a new session at all? What about keeping one session open and using a timer to trigger the repeated calls?
The screenshot is hard to read - is this Matlab 2014a? The taskmanager looks like Windows 10. Matlab 2014a is certified for Windows up to 8.1 only. Maybe an upgrade is the reliable way.

Raphaël Leclercq
Raphaël Leclercq on 29 May 2019
Thanks for your answer Jan (and all your contributions by the way).
  • "What exactly does "code called from task scheduler" mean?" A task is planified to launch matlab with a specific code in arguments every 20 minutes (cf code example).
  • "Creating code dynamically has some disadvantages". I agree with you that renaming the script during the process was not the best solution but two scripts could call the same child script at the same time.
  • Why functions are better than scripts ?
  • "Why do you assume, that the script is kept in memory?" We don't know which script is in memory but at least one by watching in the Windows command (tasklit).
% In the Task Scheduler, in the section "Program/Start a program" with the action "start a program"
D:\Software\Matlab\bin\matlab.exe
% with the argument :
Matlab -nosplash -nodesktop -r "
try,
run('D:\DonneesExternes\2.TEE\VINCI\Suivi_TBM_OVH\TEE_Glissant_OA807.m'),
catch me,
fprintf('\n %s / %s\n', me.identifier, me.message),
end;
quit();
" -logfile D:\DonneesExternes\2.T2C\SNCF\Suivi_TBM_SNCF_OVH\T2C_SNCF_Glissant_OA807.log"
  1 Comment
Steven Lord
Steven Lord on 29 May 2019
A task is planified to launch matlab with a specific code in arguments every 20 minutes (cf code example).
Would it make sense to have the same session of MATLAB run the code periodically using a timer object, to avoid the cost of starting and stopping MATLAB repeatedly?
"two scripts could call the same child script at the same time."
Can you say more about this? What's special about the script that it can't be run by two separate MATLAB sessions simultaneously? I've done this if not frequently at least sometimes to compare the results of operations in two separate versions of MATLAB when trying to diagnose a problem. [If the answer is what I suspect, that may answer your question "Why functions are better than scripts ?" at least in part.]
Why functions are better than scripts ?
This documentation page briefly discusses one of the key differences that (again, if my suspicion about your workflow is correct) may be very useful for you. Functions can accept input arguments, allowing you to run the same code on different data without changing the code. Scripts cannot accept input arguments.
We don't know which script is in memory but at least one by watching in the Windows command (tasklit).
How long does this task take to run? Does it take close to (or over) 20 minutes to run?

Sign in to comment.


Raphaël Leclercq
Raphaël Leclercq on 29 May 2019
Thanks Steven for your answer and comments.
  • "Would it make sense to have the same session of MATLAB run the code periodically using a timer object, to avoid the cost of starting and stopping MATLAB repeatedly?" It is in theory possible but I have different master scripts and I have to change the frequency frequently.
  • "What's special about the script that it can't be run by two separate MATLAB sessions simultaneously?" Codes are editing the same text file which leads to duplicate rows or loss of data.
  • "How long does this task take to run?" It depends on the data size but it could be easly over 20 minutes.
  2 Comments
Guillaume
Guillaume on 29 May 2019
Please use 'Comment on this Answer' instead of starting a new answer each time you want to comment. The more answers a question has, the less likely people (or at least I) will look at it since at least one of the answer must be correct. Your question now shows as having been answered 3 times but in fact 2 of these answers are your comments to the only answer.
Raphaël Leclercq
Raphaël Leclercq on 6 Jun 2019
Hi Guillaume, sorry about it. I will be careful next time

Sign in to comment.

Categories

Find more on Entering Commands in Help Center and File Exchange

Tags

Products


Release

R2014a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!