06-21-2024 03:20 PM
This piece of code fails intermittently on the 2nd iteration. Never fails when stepping through.
The sources files are different; but the destination is always the same, a folder.
I guessed that due to lazy writes by the OS, the 2nd iteration fails because the destination folder is being held open until the write from the 1st iteration finishes.
So I tried this:
Slows it down, but doesn't fix the problem.
Any suggestions?
06-21-2024 03:33 PM
That is weird, how large are the files? LV version and Windows?
BTW, I like your retry implementation, learnt a new technique, thanks!
06-21-2024 03:55 PM
I tried to solve a similar problem (not error 5, intermittent error 8 on a network drive) and I tried using .NET file moves instead. It seemed to work better, maybe give that a go?
06-21-2024 04:18 PM
@santo_13 wrote:
That is weird, how large are the files? LV version and Windows?
BTW, I like your retry implementation, learnt a new technique, thanks!
LV 2019
Win 10 pro
1st file is 823 KB
2nd file is 25 KB
06-22-2024 05:08 AM
@paul_a_cardinale wrote:
This piece of code fails intermittently on the 2nd iteration. Never fails when stepping through.
The sources files are different; but the destination is always the same, a folder.
I guessed that due to lazy writes by the OS, the 2nd iteration fails because the destination folder is being held open until the write from the 1st iteration finishes.
So I tried this:
Slows it down, but doesn't fix the problem.
Any suggestions?
Did you try flushing the file buffers?
06-22-2024 07:41 AM
@billko wrote:
Did you try flushing the file buffers?
The flush function takes a file refnum; but the Move function doesn't give one. So I tried Open, Flush, Close; but that didn't help.
06-22-2024 07:52 AM - edited 06-22-2024 07:57 AM
I tried replacing the Move function with Copy followed by Delete. It's the Delete that throws the error.
The VI that's running this code is a post-build action that runs as part of the build process.
The files that are being moved are ones that were created by the build. Maybe the app builder hasn't finished closing them when it calls the post-build VI.
But then why does my retry loop never succeed?
06-22-2024 08:48 AM - edited 06-22-2024 08:55 AM
Maybe the App Builder maintains an open reference to your file until the end of the post-build action? If you disable the post-build, do the build, then manually execute the post-build (with the appropriate inputs), does the file get deleted? If yes, that means the App Builder may have a bug...
The App Builder pre/post-build actions are not "strict" pre/post-build actions in the sense that something is done before the pre-build (like loading the build spec properties and the source files to build) and something is done after the post-build (like apparently closing some files and removing everything in case of fail).
This is one of the reasons why, for complex applications, I have resorted to coding my own builder VI using the App Builder API. My builder VI can then be called e.g. from a batch file and integrated in a higher-level compilation process.
With a custom builder VI, you can perform true pre/post-build operations like, before the build, modifying the build spec properties or doing some scripting on the VIs without interfering with what the App Builder loads into memory.
Regards,
Raphaël.
06-22-2024 10:16 AM
@paul_a_cardinale wrote:
The VI that's running this code is a post-build action that runs as part of the build process.
The files that are being moved are ones that were created by the build. Maybe the app builder hasn't finished closing them when it calls the post-build VI.
OK, that seems to be important information! Up until now I had no clue what you are trying to do and what are folders and what are files. 😄
I don't use pre/post build actions but do my own script that builds a source distro, an application, and an installer in sequence and at the very end moves everything to a new destination folder while renaming things. Besides the full automation (as project menu entry "build all") it also prevents problems because the build should happen in a folder that is not linked to the cloud (google drive, OneDrive, etc), while the final location should be in a monitored folder. See also this idea.
I guess one question would be if the involved hierarchy is a monitored location.
06-22-2024 03:39 PM
@raphschru wrote:
Maybe the App Builder maintains an open reference to your file until the end of the post-build action?
Seems unlikely because the problem is intermittent.