MATLAB pause does not seem to work

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

Jan
Jan le 7 Juil 2017
Modifié(e) : Jan le 7 Juil 2017
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
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
Dong-Kyeong Lee le 27 Juil 2017
>>Walter Roberson
Thank you for pointing that out. When I was writing the code on this post, I made a typo. It should be ==
>>Jan Simon
I am sorry if my question was unclear.
I am using the first method where
Check file size -> Pause -> Check file size again and compare -> Loop back
file reads in a file that is continuously growing in the designated directory. The file is growing because it is where I am writing the IF data output by a receiver. I have checked that when the file is over 10TB, it still updates the file in less than a second (and this is recognized by MATLAB)
I have tried another method. Use tic toc, and escape the loop when toc is greater than 10sec, but MATLAB seemed to run into the same problem and skipped this loop altogether after a few days.
FYI my current MATLAB is Linux 2017a
Thank you, and please let me know if I should provide any other information to resolve this issue. Also, if there is a better way to check if a file is growing or not, that would also be highly appreciated.
Jan
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.
In the original post, I posted the MATLAB output. In 60 seconds (pause of 60), the file should have grown (the file grows every millisecond). However, the file has not grown, and the file has been checked at the same time instead of after 1 minute.
(I have checked that the file is continuously growing, so the file not updating after 60 seconds is not the case here.)
I added "clock" before both file.byte, so that clock is run before and after the pause. The clock returned
2017 7 25 12 6 9.6134
2017 7 25 12 7 9.8243
2017 7 25 12 7 9.8243
2017 7 25 12 7 9.8243
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.

Connectez-vous pour commenter.

Réponses (3)

Jan
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

I tried this instead, but MATLAB seems to skip this step once in a while as well
pause_check = 1;
tic;
while pause_check
pause(10);
pause_check_var = toc
if pause_check_var>5
pause_check = 0;
end
end
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.
Dear Jan Simon,
Thank you for the comments, and I am sorry if I was not clear.
The file is growing because an IF logger is logging the data using a separate C++ code. It is just dumping all incoming data into a file, so it is growing every millisecond (about 100GB an hour)
I want to display a message and send an email if the file is no longer growing, because that would mean that the dumper or the antenna feed is problematic.
My question is, if pause is not working, is this a bug? If it is, are there are any methods to bypass this issue?
My reason behind why pause does not seem to be working is that, using the below code, (or using pause instead), when I display the file information after the supposed pause, it gives the same time. (For both file information, and clock.) When I used tic/toc, it broke after 4 days, but I did not have the display message in the code, so cannot confirm the value of toc at the time of error.
As you mentioned, I will try use the timer instead and see if the issue persists.
Another reason why I think it is the MATLAB pause, tic/toc issue is that, when I put in a large amount of loop instead of pause (Doing basic summation 10000 times), MATLAB was running fine for over a week without any problems. However, I thought that this would not be good for the machine, so decided not to use this method.
The entire code is currently using tic/toc
fnames = dir('*.bin');
while 1
oldBytes = fnames(1).bytes;
disp(fnames(1))
clock
pause_check = 1;
tic;
while pause_check
pause(10);
pause_check_var = toc
if pause_check_var>5
pause_check = 0;
end
end
newBytes(i) = fnames(1).bytes;
disp(fnames(1))
clock
if oldBytes == newBytes
disp('File not growing')
break
end
end
mail = 'xxxx';
password = 'xxxx';
server = 'smtp.gmail.com';
setpref('Internet','E_mail',mail);
setpref('Internet','SMTP_Server',server);
setpref('Internet','SMTP_Username',mail);
setpref('Internet','SMTP_Password',password);
props = java.lang.System.getProperties;
props.setProperty('mail.smtp.auth','true');
props.setProperty('mail.smtp.socketFactory.class', ...
'javax.net.ssl.SSLSocketFactory');
props.setProperty('mail.smtp.socketFactory.port','465');
% Send mail
recipients = 'xxxx'
body = 'File is not growing'
sendmail(recipients,subject,body);
Walter Roberson
Walter Roberson le 28 Juil 2017
You need to call dir() again to get the new bytes value.
Dong-Kyeong Lee
Dong-Kyeong Lee le 9 Août 2017
Even without calling dir again, it seems to update the number of bits. However, by using timer, the issue seems to have been resolved for the time being

Connectez-vous pour commenter.

TADA
TADA le 21 Fév 2019
Modifié(e) : TADA le 21 Fév 2019
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
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
Dong-Kyeong Lee le 27 Juil 2017
Dear Akhilesh Thakur,
Thank you for your comment.
The reason why I am putting a pause is because if you read the file bytes without pause, it returns the same value. I want to check if it is still recording data by checking the file size difference after a few seconds.
I do not want the pause to wait for a user input, as I want the whole process to be automated and running for an indefinite amount of time.
The current issue right now is not the case of there being a problem in the file. It is the fact that MATLAB decides not to carry out pause or tic/toc and compares the file at the same time, not at a different time. (The biggest issue is that this problem occurs randomly 1~2 times out of 1 week, so it is not predictable)

Connectez-vous pour commenter.

Catégories

En savoir plus sur File Operations dans Centre d'aide et File Exchange

Modifié(e) :

le 21 Fév 2019

Community Treasure Hunt

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

Start Hunting!

Translated by