Jump to content
Sign in to follow this  
dmkirkland

Forking

Recommended Posts

So, I'm appealing to the experts once again as I'm at my whit's end. I have written a script that processes different files and folder and creates a backup of those files using the 7za.exe file. The archiving process works perfectly. My cleanup process to remove all but the last 3 copies of the archives also works flawlessly. The issue I'm having is that it seems the script, contrary to what I assumed and hoped, seems to process without stopping. It will start the archiving processes simultaneously even though the commands are on separate lines. This presents a huge problem because the last step in the script is to have it cleanup a Temp folder created at script invocation. That Temp folder seems unable to be deleted because the files in that folder (yes they're totally different folders) seem to be in use when the script exits. I've read that AutoIT is not capable of forking or multi-threading (which now seems untrue). I don't mind the archiving processes running in parallel but if the cleanup process attempts before the archiving is complete and the temp files are ready to remove, the folder is not removed as planned which presents a problem for the cleanup process. Did I miss something with the capabilities of AutoIT in relation to forking or multi threading?

Share this post


Link to post
Share on other sites

If the archiving processes are started simultaneously you should provide an example of how your calling 7za.exe as that's likely where the problem lies. You could probably fix it so that the script it paused until the process finishes with something like RunWait or a loop to check to see if the process with specified ProccessID still exists.

If you are using RunWait or a loop to wait for the process to close, It's also possible 7za.exe is starting a separate process and closing the original causing the script to continue although I don't think 7za does this but you should still check.

If you do want to run multiple instances of 7za.exe you would have to use the Run function so the script continues (like it is now from what you say) but keep track of each PID it returns and then create a loop to check that none of the PIDs exist before the script will continue to the cleanup.

Also, AutoIT is in fact not capable of forking or multi-threading in the proper sense of it, it is however capable of starting other processes just like you are with 7za.exe, it could also start another process that is itself if you explicitly told it to. If you have files that are locked either the autoit or 7za.exe process are likely still running even if you cant see a terminal or gui, make sure you check task manager. If you still cant figure it out you can use other tools like like Process Explorer to see what process is locking a file https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer

Edited by JohnMC

Share this post


Link to post
Share on other sites

Since you didn't post your script, we can only guess.  From what you describe, you are using the Run command. as JohnMC mentioned, which allows AutoIt to spawn a process and continue.  I would add ProcessWaitClose before you start the cleaning up part of your script.  I use this with my backup script that uses robocopy to backup to multiple servers.  This will pause the script until all 7za.exe processes do not exist.  

ProcessWaitClose("7za.exe")

 

Adam

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By argumentum
      The file is now at 
      I added a WOL, tidy up, and moved the file to the uploads section of the forum.
      Suggestions are always mostly welcomed  
    • By argumentum
      Forking and threading.
      They both do stuff while another loop or event handler, does it's thing.
      Load a DLL, and ask for a function or procedure to run, and it'll do it.
      Handling all those takes time waiting, or to come up with semaphores and mutex and what not.
      So the issue at times is that we want to have all that in AutoIt and there comes the OMGs.
      To me, it all comes to run something and not get the main loop stuck waiting, unresponsive, as if frozen. ( oh, there is no threading in AutoIt, what can I do ! )
      Hence this UDFish ( I'm not good at technical writing 😕 ), that has these functions:
      #cs === User Calltips: =============================================================================================== _Fork_Startup() Init. UDF - Place on your main script once everything is declared. _Fork_StartupOnFailMsgBox([$ShowMsgBox = Default]) Default = (not @compiled), True = Show error MsgBox(), False = Do Not show error MsgBox() _Fork_Func([$sFunction = Default], [$vParameter = ""], [$sExtraCmdLine = ""], [$iUseBase64Cmd = 0], [$sVerb = ""]) Starts another Process and Execute or Call $sFunction, Returns PID. _Fork_SetReceiver([$sFunction = ""]) Register/Unregister IPC Receiver Function. _Fork_GetReceiver() Get IPC Receiver Function name. _Fork_GetParentPID() Get the parent PID. _Fork_GetWinInfos([$AutoItWinTitlePrefix = Default],[ $ForkPID = ""]) Get an array of Forked Processes _Fork_CallArgArraySeparatorChar($sChar = Default) Default = Opt("GUIDataSeparatorChar") _Fork_AutoItWinTitlePrefix([$sPrefix = Default]) Returns the prefix, or set it by passing a new string. _Fork_ForkReceiverGuiTitlePrefix([$sPrefix = Default]) Returns the prefix, or set it by passing a new string. _Fork_ProcessGetWinList($vProcess, $sTitle = Default, $iOption = 0) Enumerates Windows of a Process. _Fork_WaitForReceiver($iPidChild, [$iTimeout = 60 Sec]) wait for _Fork_SetReceiver() to load via AutoItWinSetTitle(). _Fork_WaitForFork($iPidChild, [$iTimeout = 60 Sec]) wait for _Fork_Func() to load via AutoItWinSetTitle(). _Fork_Send($vPidOrHWnd, $sMessage,[$iTimeout = 500 mSec],[$fAbortIfHung = True]) Send IPC Message to Process via PID or hWnd. _Fork_Broadcast($sMessage, [$iTimeout = 500 mSec], [$fAbortIfHung = True], [$iDelayMs = 0], [$iExcludeSelf = 1], [$WinCloseAll = 0]) Send IPC Message broadcast to all in _Fork_AutoItWinTitlePrefix(), see comments. _Fork_DuplicateHandle($dwSourcePid, $hSourceHandle, $dwTargetPid = @AutoItPID, $fCloseSource = False) Returns a Duplicate handle. _Fork_GetVerUDF() Returns the version of this UDF. _DbgAid_SetActive([$Active = Default]) Enable sending data for debug: Default = Auto (True if Win found), True = Enable, False = Disable. _DbgAid_GetActive() Query Active state. _DbgAid_GuiTitle([$sTitle = Default]) Get or Set the GUI title for the debug receiver. _DbgAid_SelfName([$sSelfName = Default]) Get or Set a short name to be identified by. _DbgAid_Send($sString[, $iForceType = Default]) Send a string to the debug GUI. _DbgAid_SendVia([$iType = Default / $e_ForkDbgAid_ViaCOPYDATA / $e_ForkDbgAid_ViaMailslot]) Get / Set _DbgAid_Send() type. #ce === User Calltips: =============================================================================================== I believe that, with these functions, one can run a function in any count of other PIDs, communicate back and forth with any of them, and a console of sorts, to send data to follow what is happening with those other instances.
      This is basically a rewrite of "Another Multi Process Helper" by @piccaso. The functions not ported, I decided to not port. The renamed functions, are renamed to simplify the understanding of what they do, from a view of a ... me  
      I did this because I'll need it in an upcoming project, and share it to aid those, that may find this, simple to implement in their code.
      Try the examples from SciTE ( or your editor ) and read the code, as there are notes explaining how it works. 
      As always, share your views and improvements. 
      If you have coding questions, kindly place them in "AutoIt General Help and Support".
      _Fork_UDF(v2019.06.29d).zip  ( current version )
×
×
  • Create New...