Repository navigation
v2.0
ParallelKit 2.0
Major changes
- Results are objects, not hashtables. Everything the kit returns (batch results,
Invoke-PkProcessWithTimeout, the dispatcher,Invoke-PkRunspaceJobs, worker-safety findings) is now a[pscustomobject], so$batch.Results | Format-Tableshows proper columns.$r.ExitCodeworks as before;$r['ExitCode'],.ContainsKey()and adding fields to a result don't. Your own command and job hashtables, and whatStart-PkProcessreturns, are still hashtables. - The worker-safety check is on by default.
Invoke-PkRunspaceJobschecks worker code before it starts anything and refuses code that breaks the worker rules. Pass-CheckWorkerSafety:$falseto turn it off. - Scriptblocks can't be passed as job values. A scriptblock made on the main thread and run inside a worker can corrupt, crash or hang the run, so it's now refused, naming the job and key. Pass the code as text and rebuild it in the worker with
[scriptblock]::Create($text).
Cmdlets are allowed in worker code
v1.0's no-cmdlets rule was a misdiagnosis. The real cause of the hangs is a scriptblock running on another runspace's thread, so there are now two worker rules instead of three, and cmdlets are fine. See #5 for the details and #10 for the checker fixes that followed.
Fixed
- Scripts run from a prompt. When a script dot-sourced the kit and was run as
.\script.ps1,Invoke-PkProcessBatchfailed every command, and any.GetNewClosure()callback calling a kit function failed too. Running withpowershell -Fileworked, which hid it. This dates back to v1.0. The kit's functions are now also defined globally. - Stopping a program stops what it started. A timeout, an overrun in
Invoke-PkProcessWithTimeout, or an abort's force-stop now kills the program's whole process tree, so its child processes no longer keep running and holding its output open. - Closing the window is announced as stopping current jobs, rather than wrongly saying it waits for them.
- Constrained Language Mode (AppLocker/WDAC-locked machines) now fails at load with a message saying why, instead of a confusing type error.
New
Invoke-PkProcessBatch -TimeoutSeconds: kill a program that runs too long. Its result hasTimedOut = $true.-OutputEncoding(batch,Invoke-PkProcessWithTimeout,Start-PkProcess, or per command): decode a program's output as UTF-8 or another code page. Without it, output stays in the console's code page, which garbles UTF-8 output on a default console.ConvertTo-PkArgumentString: build a correctly quoted command line from a list of arguments, including paths with spaces, quotes and trailing backslashes.Stop-PkProcessTree: kill one or more programs and everything they started.Get-Helpworks for every public function:Get-Help Invoke-PkProcessBatch -Full.- PowerShell 7 on Windows is supported alongside 5.1. The full test suite runs on both for every change.
Docs
- The file header now carries the version and licence notice, so a copy in your project says which version it is.
- The README covers which hosts work (consoles and editor terminals, not the PowerShell ISE), the FAQ answers common questions, and the defaults are listed where each option is introduced.
Upgrading from 1.0
- Replace
$r['Field']with$r.Fieldon anything the kit returns. - If worker code is now refused, the message says why. Fix it, or pass
-CheckWorkerSafety:$false. - Scriptblocks in job values: pass the text and use
[scriptblock]::Createin the worker. - You can now use cmdlets in worker code, so .NET workarounds written for the old rule can go.