It provides users with a way to create and communicate with child processes within an AutoIT script. It does not provide the more complex process management functions that the CoProc UDF already has. The emphasis of this UDF is instead on synchronisation and communication between the calling script and it's child processes.
It's got the same core functionality as CoProc UDF, but includes more functions around inter-process communication. Rather than compliment the CoProc UDF I found it easier to just incorporate a subset of it's functionality in this UDF.
REQUIREMENTS:
AutoIt3 3.2 or higher
LIST OF FUNCTIONS:
EXAMPLE:_ChildProc_Start($sFunction = Default, $vParameter = Default, $max_children = 0)
_ChildProc_WriteToFile($name, $text = Default, $pid = @AutoItPID)
_ChildProc_ReadFromFile($pid, $name, $fOption = 1)
_ChildProc_ReadFromAllFiles()
_ChildProc_WriteToEnvVar($sName, $vValue = Default)
_ChildProc_ReadFromEnvVar($sName, $fOption = 1)
_ChildProc_WriteToRegistry($sName, $vValue = Default, $sRegistryBase = Default)
_ChildProc_ReadFromRegistry($sName, $fOption = 1, $sRegistryBase = Default)
_ChildProc_GetChildCount()
_ChildProc_WriteToCOPYDATA($name, $text = Default, $pid = "")
_ChildProc_ReadFromCOPYDATA($name, $pid = "")
_ChildProc_ReadFromAllCOPYDATA()
_ChildProc_SendCOPYDATA($hWnd, $sData)
_ChildProc_WM_COPYDATA($hWnd, $msgID, $wParam, $lParam)
Example #1 - Parallel Processing using Environment Variables and Files
So far, I believe this example demonstrates the most efficient way to use the UDF, and yields the best performance. It's my recommendation for usage of the UDF.
The following example demonstrates how an AutoIT script can start 10 other child processes (using the ChildProc UDF), pause until the child processes have finished, and then report their output back to the main script.
The user is presented with an option to run a benchmark when the script is run. The benchmark option will report to the user the total time it took the script at the end. Results can be compared with other examples in this post.
The flow of the script is as follows. A loop is performed to run a repetitive task in multiple child processes (_ChildProc_WriteToEnvVar and _ChildProc_Start calls). Variables and values are defined in each _ChildProc_WriteToEnvVar call to be passed into the "MultiProcessFunction". The variable names are all unique, in that each one is prefixed with the number of the current iteration. This ensures that variables from previous calls aren't accidentally overwritten.
The child processes (in parallel within the "MultiProcessFunction" function) consume the variables set by the "main" calling script, using "_ChildProc_ReadFromEnvVar". The last line of the "MultiProcessFunction" function (_ChildProc_WriteToFile) writes the output of the child process to a unique file (named according to it's PID) to be collected later by the main script.
Once the main script completes it's first loop (and all child processes have started) it then goes into a "while" loop, calling "_ChildProc_GetChildCount" periodically until there are no child processes left (ie. they have all ended). This is a synchronisation point to tell the main script to then continue and collect the output from all the children (using "_ChildProc_ReadFromAllFiles").
Note that compiling this example, and running it as an executable, should produce the same result as above.
This example benchmarks at 1056 ms on my dual-core 2.5MHz Thinkpad.
ChildProc_EnvVar_File_test.au3 2.1K
829 downloadsExample #2 - Parallel Processing using Environment Variables and WM_COPYDATA
The following example demonstrates how an AutoIT script can start 10 other child processes (using the Windows WM_COPYDATA functions), and retrieve the output of each process as it finishes back to the main script.
The user is presented with an option to run a benchmark when the script is run. The benchmark option will report to the user the total time it took the script at the end. Results can be compared with other examples in this post.
The example is quite complex, due to the nature of trying to implement WM_COPYDATA across multiple concurrent processes. WM_COPYDATA is synchronous in nature, much like a pipe attached to a process / window. For multiple processes to communication through it to other processes / windows, the data transfer must be synchronised across all processes, so that no data is lost. The synchronisation process seems to be resource expensive, and slows the script significantly.
Note that there seems to be a synchronisation issue in this example in that many times it "falls out of sync" and leaves some child processes pending forever. If this happens, you'll need to manually kill the AutoIt3.exe processes that have hung, using Windows Task Manager. My apologies. Since this example is much slower than Example #1 above, I'm not in a hurry to fix it (it's not my preferred method of inter-processs communication).
This example benchmarks at 6326 ms on my dual-core 2.5MHz Thinkpad.
ChildProc_COPYDATA_test.au3 2.39K
640 downloadsExample #3 - Sean's eBay Bargain Hunter
This example I've stored in a topic all it's own. Mainly because I want to version control it as a separate application.
It's a brilliant demonstration of the power of Example #1 above, applied to an actual app. Click here to visit and download the Bargain Hunter.
I have previously used this app. to conduct over 100 parallel searches in eBay, with all processes returning their results in as little as 60 seconds (which I think is pretty cool).
DOWNLOAD:
Latest Version - v0.4 (02/06/10)
ChildProc.au3 24.84K
1068 downloads
Edited by seangriffin, 02 June 2010 - 05:41 AM.






