[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: Editing DO files while it is being executed
Dave Ewart (email@example.com) asked about the behavior of Stata
while executing do-files that are being edited and saved-over while
they are being executed:
> Something one of our staff noticed is that 'strange things' can happen
> if one edits a running DO file. For example:
> 1. Start a Stata job with "do somefile.do";
> 2. While the job is still running, edit somefile.do in an editor, say,
> by adding some additional commands to the end of it;
> 3. See the Stata job *execute those additional commands*, rather than
> executing the contents of the DO file as it was when the job started!
> This behaviour happens on both Stata versions we have here: Stata 8 for
> Windows and Stata 9 for Linux.
> I used 'strace' to see what Stata was actually doing. It appears that
> Stata reads the DO file in 512-byte blocks and only reads the next block
> when it needs to (and "when it needs to" can be minutes, hours or even
> days later).
> This behaviour of Stata seems strange: why doesn't it read the whole DO
> file at the start (which will only happen if the whole DO file is <512
> bytes in size)?
Dave is correct. This is exactly what Stata does. Stata has two
1) read the file one piece at a time, pulling each piece when it
2) read the whole file at once
Each approach has advantages and disadvangates.
The reason Stata does not take approach #2 is that the do-file could
be many thousands of lines long and reading it all at once could
consume a large amount of memory. Stata prefers to leave that memory
available for the data and processing required during the analysis
specified by the do-file.
The same behavior can been seen in other software. For example,
it is not a good idea to edit a Unix shell script while it is running,
for you may break it or change the intended behavior if you overwrite
it while it is still running.
We will most likely increase the buffer size for approach #1 to
something larger than 512 bytes in a future update. However, we
still recommend that users do not edit and overwrite do-files while
they are running.
Also, we consider it good practice to preserve do-files so they can be
re-run to reproduce results. Obviously, if a do-file is a work in
progress and is being debugged, it will go through changes until it is
finalized. However, if a do-file produces results which a user cares
about, that do-file should be left as-is so that those results can be
reproduced later. In this way, do-files and their results are kept in
sync. A variation on a do-file needed for different results should be
saved under a different name.
* For searches and help try: