Jump to content
Sign in to follow this  
sivaramanm

AutoIt Program/.EXE completed execution, but process still running

Recommended Posts

sivaramanm

I am launching multiple instances (16) of a compiled exe with different command line parameters.

Even though the program completed its execution, (i have _filewritelog for execution start & complete) the program is still running in the Process Explorer (not always but randomly). I couldn't find any specific pattern of when and at what circumstances this happens.

I have a clear Exit/Return commands at the end of the program, but still it doesn't help.

When I tried with the original .au3 script itself instead of compiled exe, same behavior is observed.

Kind of struck of how to proceed further...Any help would be greatly appreciated!

Update-1:

When I enabled "TrayIconDebug" and after few minutes of running the tray icons went away(which means program completed) but still the process exist and running in the process explore. PFA the snapshot.

Launch Instance (Wrapper) Program:

============================

AutoItSetOption("TrayIconDebug",1)
#include "Include_Hourly_4GCORE.au3"


Global $BaseTime = ""
Global $NoOfHoursToCheck4ReRun = 24*4


Global $TimeStamp = @MON & @MDAY & @YEAR & "-" & @HOUR & @MIN & @SEC
Global $LogDir = @ScriptDir & "\ScriptLogs\"
Global $LogFile = "TMP2_Hourly-4GCORE-Wrapper-Log-" & $TimeStamp & ".txt"
Global $LogPathNFile = $LogDir & $LogFile

Launch_MissingFile_Update()

Exit

;Functions 
; This function first launches 16 instances with different command line params and as and when any of the instances completed execution, it then launches additional instances until
; all instances are launched
;

Func Launch_MissingFile_Update()
WriteLog("[Info]    Launching parallel parser for Missing Files Update...")


$FileCntArray=DirGetSize($Temp2Dir,1)
$Total_ReRunFiles=0
If Not @error Then
$Total_ReRunFiles=$FileCntArray[1]-1
WriteLog("[Info]    Found " & $Total_ReRunFiles & " entries to ReRun")
EndIf


    Local $CSVSearch = FileFindFirstFile($Temp2Dir & $MissingFileExport)
    If $CSVSearch = -1 Then
        WriteLog("[Error]   No files/directories matched the search pattern - " & $Temp2Dir & $MissingFileExport)
        Return $C_FAIL
    EndIf


    Local $sFileName = ""


Local $FileCnt=1
    While 1
        $sFileName = FileFindNextFile($CSVSearch)
        ; If there is no more file matching the search.
        If @error Then
WriteLog("[Info]    Launched all the CSV Files...")
ExitLoop
EndIf


$sFileNameNPath = $Temp2Dir & $sFileName
;$PID=Run(@AutoItExe & " " & $BaseDir & "ReRun_MissingFiles.au3 " & $sFileNameNPath & " " & $FileCnt,"",@SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
$PID=Run($BaseDir & "TMP2_ReRun_MissingFiles.exe " & $sFileNameNPath & " " & $FileCnt,"",@SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)
Assign("ReRun_PID_" & $FileCnt,$PID)
WriteLog("[Info]    Adding PID# [" & $FileCnt & " Of " & $Total_ReRunFiles & "] " & $PID)


If $FileCnt >= $TMP2_NoOfReRunInstances Then
While 1
$NoOfActivePIDs=0
For $z=1 To $FileCnt
If ProcessExists(Eval("ReRun_PID_" & $z)) Then $NoOfActivePIDs += 1
Next
If $NoOfActivePIDs < $TMP2_NoOfReRunInstances Then ExitLoop
WEnd
EndIf


Sleep(2000)
$FileCnt += 1
    WEnd
$FileCnt -= 1
    ; Close the search handle.
    FileClose($CSVSearch)


WriteLog("[Info]    before loop filecnt is " & $FileCnt)
WriteLog("[Info]    Waiting for all ReRun Processes to complete...")
While 1
$NoOfActivePIDs=0
For $z=1 To $FileCnt
If ProcessExists(Eval("ReRun_PID_" & $z)) Then
$NoOfActivePIDs += 1
If @SEC=01 And Sleep(50) Then WriteLog("[Info]    PID# " & $z & " - " & Eval("ReRun_PID_" & $z) & " exists.")
EndIf


Next
If $NoOfActivePIDs <= 0 Then ExitLoop
;~  If @SEC=01 And Sleep(1000) Then WriteLog("[Info]    Still " & $NoOfActivePIDs & "  active PIDs exists...")
WEnd


WriteLog("[Info]    All [ReRun] Processes completed...")
EndFunc

Actual Program:

============

#include "Include_Hourly_4GCORE.au3"

AutoItSetOption("TrayIconHide",1)

;Map command-line parameters
Global $InputCSVFile=$CmdLine[1]
Global $InstanceNo=$CmdLine[2]

Global $LogDir = @ScriptDir & "\ScriptLogs\"
Global $LogFile = "TMP2_Hourly-4GCORE-Log-" & $InstanceNo & ".txt"
Global $LogPathNFile = $LogDir & $LogFile

WriteLog("[Info]    Starting the ReRun Of " & $InstanceNo_Orig) ;Log the execution start
ReRun_FileUpdateLog_Parallel($InputCSVFile)
WriteLog("[Info]    Done with ReRun Of " & $InstanceNo_Orig) ;Log the execution complete
Exit


Func ReRun_FileUpdateLog_Parallel($CSVFile)
;
;
; Do some processing here and return
;
;
Return
EndFunc

post-79561-0-64874200-1407859754_thumb.p

Edited by sivaramanm

Share this post


Link to post
Share on other sites
November

Hi there,

I believe that your issue is that you run 16 child process with run command regarding Autoit3wrapper.exe :

$PID=Run($BaseDir & "TMP2_ReRun_MissingFiles.exe " & $sFileNameNPath & " " & $FileCnt,"",@SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD)

And i bet that you are running some 3rd party application in the second script.

If you what a "process free exit program" you have to get control on the exit of your child processes, and exit the main script just when other processes are over.

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites
sivaramanm

Yes. In order to get away with any bugs present in the AutoITWrapper.exe only I tried the compiled exe version of .au3(Which i hope will not involve AutoITWrapper.exe). But there also same behavior only observed.

In the second script(child process), I am invoking few perl and windows command through Run. As i said, from the logs it is clear that the script completed its execution, but not sure why the process is not exiting...!

Share this post


Link to post
Share on other sites
November

Can't you concentrate all in one script?

If you have a cascade of runs, it is really difficult to have a "consistant" way to monitor child processes.

Can you summarize what your script does?

Probably re-arranging your script will make you have more control.

Cheers


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites
sivaramanm

I want to have 16 different set of instances running in parallel...Since I can't do that without thread support I went in with two script approach.

Basically in the child process, I am processing few CSV files and importing those files into mysql DB with the help of Perl Script (which parses and updates into mysql).

Share this post


Link to post
Share on other sites
November

I want to have 16 different set of instances running in parallel...Since I can't do that without thread support I went in with two script approach.

Basically in the child process, I am processing few CSV files and importing those files into mysql DB with the help of Perl Script (which parses and updates into mysql).

And connections to the MySQL are terminated?


Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Share this post


Link to post
Share on other sites
sivaramanm

Yes ofcourse.I wait for a certain period of time and if it exceeds then i kill that process and exit!

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  

×