bugGNU Octave - Bugs: bug #60122, Save and Run in editor does not...

 
 

bug #60122: Save and Run in editor does not always save

Submitted by:  None
Submitted on:  Fri 26 Feb 2021 01:48:14 AM UTC  
 
Category:  GUI Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  None Assigned to:  None
Originator Name:  Bill Eaton Originator Email:  -email is unavailable-
Open/Closed:  Open Release:  6.2.0
Operating System:  Microsoft Windows

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Sat 13 Mar 2021 11:34:42 PM UTC, comment #9: 

100 ms refresh sounds about right.

Rik <rik5>
Project Administrator
Sat 13 Mar 2021 09:04:20 PM UTC, comment #8: 

I plan to test the timestamp immediately after saving and start the repeated testing only if this test is negative. However, I expect that this first test will already be positive in the majority of cases. But you are right, the "sampling time" for the repeated test could also be 100ms. If the timestamp did not change after 2s (too short?), 'clear -f FUNCTION_NAME' could be carried out before running the file.

Torsten Lilge <ttl>
Project Member
Sat 13 Mar 2021 08:18:43 PM UTC, comment #7: 

@Torsten: That would probably work, and would get around the issue of nested functions and subfunctions not being cleared.

I bet you want to make the repeat timeout shorter than 500 ms.  People are going to be impatient when they click "Save and Run" and a half a second seems laggy.

Rik <rik5>
Project Administrator
Sat 13 Mar 2021 06:46:51 PM UTC, comment #6: 

Would it be safer to check for the changed file timestamps after saving and before running the file? This could be done by reading the file stat and repeat this every 500 ms or so until the timestamp has changed or a timeout is reached.

Torsten Lilge <ttl>
Project Member
Fri 12 Mar 2021 11:03:35 PM UTC, comment #5: 

This could be a problem specifically with Windows and, possibly, specifically with networked drives.

When you first run an m-file, Octave parses it and stores an internal representation of the code.  It also records the last modification time of the file.

Now, when you go to run a function a second time Octave first looks into it's cache of parsed code to see if the function exists.  If it does, it then looks at the timestamp of the m-file and compares it to the recorded timestamp.  If they are the same, nothing has changed and Octave can go ahead and use the cached code.  Otherwise, it has to go out to the disk, parse the new code, and build the internal representation which it then runs.

There are two issues with your current setup.  First, some Windows file systems (for example, VFAT) store timestamps with only 2-second resolution (see https://unix.stackexchange.com/questions/470856/timestamps-of-files-copied-to-usb-drive).  So if you save a file, make a quick change, and then save again Octave may not even notice that a change has been made.  If you can, you might check if you can use NTFS as a file system since it has 100 nanosecond resolution.

Second, if the drive is networked there is going to be some time between issuing a save command and when the timestamp on the disk is actually modified.  It could be that Octave issues a save command to the operating system, which returns quickly because it has sent the command off on the network.  Octave then goes to run the script which begins by checking the timestamp.  Maybe the operating system returns the old timestamp before the write command is executed.  This seems perfectly plausible because once you go on to an IP network order of packets is not guaranteed.

There is a way that we could address this on our side.  The sequence of commands is

1. Save
2. Run

Since the expectation, intention is that the programmer must have made a change and that is why the Save operation is required, it should be okay to invalidate Octave's local cache and force the file to be re-parsed.  In this case, the command sequence would be

1. 'clear -f FUNCTION_NAME'
2. Save
3. Run

It's not perfect if the m-file has nested function or subfunctions, since those should be cleared as well.  But maybe this is a step in the right direction.

Rik <rik5>
Project Administrator
Mon 08 Mar 2021 11:00:26 PM UTC, comment #4: 

Whoa. The behavior is even stranger than I thought. Editor saves the file. The file is actually saved. A second editor will prompt me for reload. Modification icon does disappear. But then Octave runs an old copy of the script.

If instead, I press the Save button and then press the Save and Run button, the corrected version of script runs. That's what I've been doing as a workaround.

The only question left now is whether this behavior is only for network drives.

Bill Eaton <wpeaton>
Mon 08 Mar 2021 09:07:47 PM UTC, comment #3: 

Just to be clear. Having the file in question open in a second editor is just for testing whether this editor detects a file change (what octave then is not doing) or whether the file is actually not saved by the octave editor.

Torsten Lilge <ttl>
Project Member
Mon 08 Mar 2021 09:00:50 PM UTC, comment #2: 

Torsen Lilge,

These are some good questions. Right now I can only answer 1. I'll do some more work to figure out 2 or to edit in another editor.

So far I have been doing all of my work with files on a network drive. I will do some more work from local drive and also to see if modification icon disappears after Save & Run button is pressed.

Bill Eaton <wpeaton>
Sat 06 Mar 2021 05:31:54 PM UTC, comment #1: 

Thanks for the report. Two questions:

  1. Is the file to be saved located on a local or network drive?
  2. You are saying that the file is not saved. But the modification icon on the editor tab is disappearing?

Could you open the file in an external editor which automatically reloads modified files or at least detects a mofication? When you edit and save the file in Octave's editor, does the external editor reloads the new version or detects the file change?

Torsten Lilge <ttl>
Project Member
Fri 26 Feb 2021 01:48:14 AM UTC, original submission:  

The save and run button in the editor sometimes fails to save and runs an older version of the script. This also applies to 6.1.0.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by wpeaton (Posted a comment)
  • -email is unavailable- added by ttl (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    No changes have been made to this item

    Back to the top


    Powered by Savane 3.6