ShawnW Posted November 17, 2010 Share Posted November 17, 2010 I have a script that may run more than once instance at the same time. I want the script to sleep until other instances are done. I was thinking something like this would work. $ScriptsRunning = ProcessList("script.exe") For $i=1 To $ScriptsRunning [0][0] $currentScriptsPID = ; ??? How do I get this if it might share a name with other instances of the process. If $ScriptsRunning [$i][1] <> $currentScriptsPID Then ProcessWaitClose($ScriptsRunning [$i][1]) Next Link to comment Share on other sites More sharing options...
Developers Jos Posted November 17, 2010 Developers Share Posted November 17, 2010 (edited) Looking for @AutoItPID ? One thing to remember is that 2 extra instances of a scripts waiting for the first one will get into a deadlock situation. Edited November 17, 2010 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
wakillon Posted November 17, 2010 Share Posted November 17, 2010 You can also use a condition like this #include <Misc.au3> Do Sleep ( 50 ) Until Not _Singleton ( @ScriptName, 1 ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Developers Jos Posted November 17, 2010 Developers Share Posted November 17, 2010 (edited) You can also use a condition like this #include <Misc.au3> Do Sleep ( 50 ) Until Not _Singleton ( @ScriptName, 1 ) Did you test this? The Until logic is incorrect and has the same deadlock issue. Edited November 17, 2010 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ShawnW Posted November 17, 2010 Author Share Posted November 17, 2010 One thing to remember is that 2 extra instances of a scripts waiting for the first one will get into a deadlock situation.Yeah thought of that which is why each instance gets a list of others with the same name at the time it starts. It only waits for those instances (minus itself) to stop. The next instance will have a larger array of processes to wait for, but the one currently running will not see any that start after it. Link to comment Share on other sites More sharing options...
Developers Jos Posted November 17, 2010 Developers Share Posted November 17, 2010 Yeah thought of that which is why each instance gets a list of others with the same name at the time it starts. It only waits for those instances (minus itself) to stop. The next instance will have a larger array of processes to wait for, but the one currently running will not see any that start after it.Yea that is true and should work indeed as long as you do not refresh the process array.Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
wakillon Posted November 17, 2010 Share Posted November 17, 2010 (edited) Did you test this? The Until logic is incorrect and has the same deadlock issue. You're right ! #include <Misc.au3> Do Sleep ( 50 ) Until _Singleton ( @ScriptName, 1 )=1 Edited November 17, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Developers Jos Posted November 17, 2010 Developers Share Posted November 17, 2010 You're right ! #include <Misc.au3> Do Sleep ( 50 ) Until _Singleton ( @ScriptName, 1 )=1 It is still wrong... try it SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
wakillon Posted November 17, 2010 Share Posted November 17, 2010 It is still wrong... try it Ok ! you win ! I have tried in a while loop with differents way but it doesn't want to work !This function is supposed to indicate if another process with the same name is running !That's strange... AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Developers Jos Posted November 17, 2010 Developers Share Posted November 17, 2010 (edited) Simply: #include <Misc.au3> Do Sleep ( 50 ) Until _Singleton ( @ScriptName, 1 ) MsgBox(1,"test",_Singleton ( @ScriptName, 1 )) _Singleton() returns a handle, not 1. Compile it and run it 3 times.... you will see 1 msgbox and after you close it it will have a deadlock situation with the other 2 instances. Jos Edited November 17, 2010 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
wakillon Posted November 17, 2010 Share Posted November 17, 2010 Simply: #include <Misc.au3> Do Sleep ( 50 ) Until _Singleton ( @ScriptName, 1 ) MsgBox(1,"test",_Singleton ( @ScriptName, 1 )) _Singleton() returns a handle, not 1. Compile it and run it 3 times.... you will see 1 msgbox and after you close it it will have a deadlock situation with the other 2 instances. Jos So there is no solution ? Or he add a condition to determine the winner ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Developers Jos Posted November 17, 2010 Developers Share Posted November 17, 2010 So there is no solution ?Or he add a condition to determine the winner ! The original posted code should work fine when modified comparing to @AutoItPid.The Second instance of script will then wait for only the first one.The third instance will wait for both the first and second instance.etc... SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
wakillon Posted November 18, 2010 Share Posted November 18, 2010 (edited) @Jos The original posted code should work fine when modified comparing to @AutoItPid. The Second instance of script will then wait for only the first one. The third instance will wait for both the first and second instance. etc... I'm ok with the deadlock situation... but i'm not with your script example #include <Misc.au3>Do Sleep ( 50 )Until _Singleton ( @ScriptName, 1 )MsgBox(1,"test",_Singleton ( @ScriptName, 1 )) _Singleton() returns a handle, not 1. Compile it and run it 3 times.... you will see 1 msgbox and after you close it it will have a deadlock situation with the other 2 instances. your script say : Sleep until another handle is detected, but what ShawnW want it's : Sleep until there is no other process with same name ! And the first instance exit because it detect one of 2 others, ok but why after the 2 others are not detected themself ? If you kill manually one, the last don't stop and is well waiting for another process ! that's not what ShawnW want ! So i tried like that with the string function for well compare return value from handle or zero and a GUICtrlCreateEdit for get return in "live" [/size][/color][/size] [size="3"][color="#1C2837"][size=2] #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <Misc.au3> #include <WindowsConstants.au3> Local $myedit, $msg GUICreate ( "My GUI edit", 250, 250 ) $myedit = GUICtrlCreateEdit ( "", 20, 20, 210, 210, $ES_AUTOVSCROLL+ $WS_VSCROLL ) GUISetState ( ) Sleep ( 4000 ) While 1 $_Singleton = String ( _Singleton ( @ScriptName, 1 ) ) GUICtrlSetData ( $myedit, $_Singleton & @CRLF, 1 ) $_StringLen = StringLen ( $_Singleton ) GUICtrlSetData ( $myedit, '$_StringLen : ' & $_StringLen & @CRLF, 1 ) If $_StringLen <> 1 Then ; other process like 0x0000011C Sleep ( 50 ) Else GUICtrlSetData ( $myedit, 'exiting' & @CRLF, 1 ) Exitloop ; no other process with same name EndIf $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd MsgBox ( 1, "test", $_Singleton ) GUIDelete ( ) Exit[/size][/color][/size] [size="3"][color="#1C2837"][size=2] Like Jos said Compile it and run it 3 times.... So if you try this you will see the first execution detect once a handle but after exit because it detect nothing... And after the 2 others instances detect nothing ( even one time ) and exit... So, _Singleton function is strange ! I don't know if you understand my demonstration but i think this function is not clear ! Edited November 18, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
ShawnW Posted November 18, 2010 Author Share Posted November 18, 2010 Never tried the _Singleton since as Jos said, my original code worked once he helped me find the @AutoItPID macro. By the way I forgot to say thanks! -Shawn Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now