MATLAB pause does not seem to work
Afficher commentaires plus anciens
I am currently using the pause function to see if a file is growing or not.
while 1
file1 = file.bytes
pause (60)
file2 = file.bytes
if file1 == file2
display('File stopped growing')
break
end
end
However, after running it for 1~2 days, MATLAB skips the pause and thinks that the file is not growing anymore. Is there a way to fix this issue?
For example, I get this message:
name: 'xxx.bin'
date: '07-Jul-2017 13:03:14'
bytes: 7.981710180352000e+12
isdir: 0
datenum: 7.368835439120370e+05
name: 'xxx.bin'
date: '07-Jul-2017 13:03:14'
bytes: 7.981710180352000e+12
isdir: 0
datenum: 7.368835439120370e+05
7 commentaires
The question is not clear. What is "file.bytes"? How has "file" been created? How is it updated between the calls? The posted code does not create the shown output. Or is "file.bytes" a struct created by older versions of dir()? Is the shown message the output of
file1 -> pause -> file2
or of
file2 -> next loop -> file1 ?
In the latter case it is not surprising, that the times are equal.
You are testing the size of a 8TiB file with a polling loop? This is a really strange method. Do you have any evidence that such a huge file is flushed correctly inside a time limit of 60 seconds?
Walter Roberson
le 7 Juil 2017
I do not understand why you say a file has stopped growing if two file sizes are not equal ?
Dong-Kyeong Lee
le 27 Juil 2017
Dong-Kyeong Lee
le 27 Juil 2017
Jan
le 28 Juil 2017
I still cannot imagine what "Matlab skipped this loop" means. Why do you assume this? What do you observe? Which problem should the code solve? File greater than 10 TB are unusual and I do not have any experiences with file systems for such huge files.
Dong-Kyeong Lee
le 28 Juil 2017
Jan
le 28 Juil 2017
No, you did show some output and some code, but the output cannot be created by the shown code:
file1 = file.bytes
pause (60)
file2 = file.bytes
It is not clear why you assume "file.bytes" to have changed here. And this code will not produce the message:
name: 'xxx.bin'
date: '07-Jul-2017 13:03:14'
bytes: 7.981710180352000e+12
isdir: 0
datenum: 7.368835439120370e+05
which seems to be the output of a dir command.
Now you have posted some output from a clock command:
2017 7 25 12 6 9.6134
2017 7 25 12 7 9.8243
2017 7 25 12 7 9.8243
But we have to guess which code creates this output.
I still assume, that there is a bug in your code. You still did not answer the questions for clarifications I've posted 3 week ago: How has "file" been created? How is it updated between the calls?
You wrote "the fact that MATLAB decides not to carry out pause or tic/toc". But it is still not clear, why you assume that this is a fact.
Réponses (3)
Jan
le 28 Juil 2017
1 vote
Perhaps it is a kind of overflow in a time counter of the pause command. I do not understand, what you did with tic/toc, please post the code if this is important.
I'd suggest to use a timer instead of a pulling loop with pause.
5 commentaires
Dong-Kyeong Lee
le 28 Juil 2017
Jan
le 28 Juil 2017
What is the purpose of this code? You check if the first call to pause waits for more than 5 seconds. All subsequent calls to toc will reply something like 10, 20, 30, ... seconds. Maybe the internal counter uses a signed integer and you get an overflow. So what about:
pause_check = 1;
while pause_check
tic;
c1 = clock;
pause(10);
c2 = clock;
pause_check_var = toc;
if pause_check_var < 9.9
disp(c1)
disp(c2)
disp(etime(c2, c1))
% Perhaps you have shadowed "pause.m"?
which pause -all
pause_check = 0;
end
end
Unfortunately you still did not explain, what the program should do. Do you want to display a message in the command window, if the file does not grow anymore? Then what about using the last access time in the file browaser of the operating system? Or are you interested in possible internal problems of the pause command for a bug report? What is the problem you want to solve? Would a timer be a solution?
We are discussing this problem for 3 weeks now and it is still not clear to me which problem you want to solve, which code you run to get the shown output and how you exactly get to your impression, that there is a problem with pause. There is a great potential to improve the efficiency of the discussion.
Dong-Kyeong Lee
le 28 Juil 2017
Walter Roberson
le 28 Juil 2017
You need to call dir() again to get the new bytes value.
Dong-Kyeong Lee
le 9 Août 2017
I just encountered the exact same weird issue...
aparently you can switch pause on and off, and i got some piece of code from somewhere which turned it off without noticing. which broke a few unit tests... wasted half a day debugging my timers before realizing pause didn't do anything :\
pause off
pause(10) % pause doesn't do anything
pause on
pause(10) % pauses for 10 sec
p = pause()
p =
'on'
Akhilesh Thakur
le 27 Juil 2017
0 votes
The code you wrote is hard to understand. If your file is growing or changing why there is a pause between file1 and file 2. If it says the file is not growing definitely there must be some external thing working on it. Matlab doc says pause temporarily stops MATLAB® execution and waits for the user to press any key. So look for that. Another thing is oldState = pause(state) returns the current pause setting and sets the pause state as indicated by state, you can use this and always do a printf to check whetehr there is a problem in the file.
1 commentaire
Dong-Kyeong Lee
le 27 Juil 2017
Catégories
En savoir plus sur File Operations dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!