Repository navigation
Releases
v4.3
With this, I consider the kit stable and ready for deployment. All reviews between 4.2 and 4.3 only turned up uncommon to extremely rare edge cases, so I expect this will be the final update unless a user-reported issue comes in. Cheers!
ParallelKit 4.3
After updating, start a new PowerShell window. The kit's compiled parts changed, so a session that loaded an older copy will refuse to load this one.
A fix release. Killing a program's tree (a time limit, an abort's force-stop, a failed start, -KillTreeOnExit) now says when it may have left something running, instead of reporting a clean stop. An abort requested from code or a callback stops new work straight away. Two inputs that used to be mangled without a word are now errors: an argument with a NUL character, and a runspace job with two keys that differ only in case. A list of arguments for a drive-relative cmd.exe path is quoted for cmd.exe. Programs and working folders past Windows' path limit start by their 8.3 short names, and -WorkerScript ${function:Name} works. -MaxOutputChars no longer drops a surrogate pair that fits.
Fixed
- A list of arguments is quoted for
cmd.exeunder a drive-relative path too. Given-FilePath 'C:cmd.exe'(orC:cmd), the kit quoted a list the ordinary way instead of the waycmd.exereads it, so an element holding a quote and&could makecmd.exerun a second command. Full and bare paths (cmd.exe,C:\Windows\System32\cmd.exe) were already quoted forcmd.exe. (#113) - An abort requested from code or a callback stops new work straight away. An abort requested between the engines' own checks, by
Request-PkAbortbefore a run or from a callback (-ResultHandler,-NextJobProvider,-PollCallback,-JobFinalize), let the run start one more round of workers or programs, or ask-GroupProviderfor more groups, before it stopped. The engines now check for an abort before each start and before asking for more work, so an abort from a-JobStarter, or a Ctrl+C while the dispatcher is starting programs, starts nothing more either, and one from-GroupProvider,-JobBuilder,-GroupCompleteCallbackor-GroupReleaseCheckasks for no more groups. A job a-NextJobProviderreturns from the same call that requests the abort still runs. (#114, #121, #128) - A failed start no longer leaves behind what the program started, if the program had already exited. When a program's output readers couldn't start (4.2 stops the program then), or a custom
-JobStarterthrew after starting its program, the kit stopped the program, but a program that had already exited was passed over, along with anything it had started. That's now ended too, through the program's own Job Object. (#115) -WorkerScript ${function:Name}works. Given a function's own scriptblock,Invoke-PkRunspaceBatchdidn't see its parameters, so a job with values was refused ("doesn't declare it"), a declared$CancelTokenwasn't filled in, and mandatory parameters weren't checked up front. The worker-safety check also flagged a$script:at the function's top level, which is fine there, as in a{ }block. Bothfunction f { param(...) }andfunction f(...)now work. (#117)- An argument with a NUL character is an error instead of being cut off. Windows reads a command line up to its first NUL, so the argument was cut short there and every argument after it was dropped, without a word. Now it's an error before the program starts, in a list or a string, for any program (in a batch, that command's
StartError). (#119) -KillTreeOnExitno longer says a program it killed "has no Job Object of its own". With-KillTreeOnExit, a program the kit killed for its time limit (the dispatcher's, the batch's orInvoke-PkProcessWithTimeout's) or in an abort's force-stop got that warning, though nothing was wrong: the kill had already ended what the program started. (#122)- A case-sensitive job's
canceltokenreaches the worker.Invoke-PkRunspaceBatchput its own token in place of acanceltokenkey from a case-sensitive hashtable ([hashtable]::new()). A job with two keys that differ only in case, such asIdandid, is now refused with a message naming them, rather than the worker silently getting only the later one. (#126) -MaxOutputCharskeeps an emoji or other surrogate pair that fits. Output exactly as long as the cap lost a pair that fell where the kept start ends:a😀bunder a cap of 4 came back asab, with 2 characters counted as dropped. (#127)- A failed start says when what its program started may still be running. When a program's output readers couldn't start, or a
-JobStarterthrew after starting its program, the kit said the program was stopped even when Windows wouldn't end the program's own Job Object, or an exited program had none, so what it started could still be running. The failure now says so. (#131) - A time limit or force-stop warns when it may have left something running. When a killed program had no Job Object of its own (Windows refused one, or
NoJob), or Windows wouldn't end it, the kill went totaskkill /T, which misses a child whose parent has already exited, without a word. That's now warned about once per session (a failed start that had to kill such a program says so in its error), andInvoke-PkProcessWithTimeout's time-limit error says when the program couldn't be killed rather than that it was. (#133, #134)
Changed
-KillTreeOnExitwarns when Windows won't end what a program left running. It ends a program's leftovers through the program's own Job Object. If Windows refused to end that Job Object, nothing said so, and the leftovers kept running (showing only as a stream timeout if they held the program's output). It now warns, once per session, naming the process. They still end when PowerShell does. (#116)- A program or working folder whose path is too long for Windows starts by its 8.3 short name. Windows won't start a program by a path of 260 characters or more, or in a working folder of 259 or more, even with long paths enabled, so these starts failed ("The filename or extension is too long", "The directory name is invalid"). The kit now tries once more with their short names (
C:\PROGRA~1\...). That works where the drive makes short names, usually the system drive; elsewhere the start fails with Windows' error as before, now followed by a sentence saying the path's length is why. (#125)
Documentation
- The command reference's
ConvertTo-PkArgumentStringrow namescmd.exeamong the programs a list is quoted for, as the Arguments section already did. (#120) - The Arguments section says what
cmd.exe's delayed expansion does to a quoted argument. With it on,!NAME!is expanded inside quotes, a^in an argument that holds a!is dropped, and in a batch file an unset!NAME!or a lone!is dropped too; the kit's quoting can't stop that, as with%NAME%. (#130)
v4.2
ParallelKit 4.2
After updating, start a new PowerShell window. The kit's compiled parts changed, so a session that loaded an older copy will refuse to load this one.
A fix for a program the kit could lose track of, and a warning where -KillTreeOnExit used to do nothing silently. 4.2 is also the first version on the PowerShell Gallery since 4.0: 4.1 was released on GitHub only.
Fixed
- A program whose output readers can't start is stopped, and its start reported as failed. Once a program was running, the kit started a thread to read each of its output streams. If one of those threads couldn't start (Windows out of resources, say), the program kept running with nothing reading its output and nothing holding on to it: the batch and the dispatcher never saw it. Now the program and anything it started are stopped, and the command gets a
StartErrorlike any other failed start. (#111)
Changed
-KillTreeOnExitwarns when it can't reach a program's tree. It works through the Job Object the kit gives each program it starts. For a program without one (Windows refused it, the kit is running without Job Objects, or a custom-JobStarterstarted the program itself), it used to do nothing, silently. It now warns, once per session.StartModeCreatedInJobdescribes how programs are started, not whether each one got its own Job Object. (#111)
Documentation
- "Choosing limits" says that each running program takes two threads, one reading each of its output streams, so hundreds of programs at once mean hundreds of threads. (#111)
v4.1
The release file was lost due to an outage at the time of release, however 4.2 was pushed shortly after so I won't be redoing the 4.1 release.
ParallelKit 4.1
A small release: the dispatcher now warns when -GroupProvider outputs more than one value in a call, which is almost always a stray value or a list returned without its leading comma. The kit's compiled parts didn't change, so a session that has 4.0 loaded can load 4.1 without a new window.
Added
- The dispatcher warns when
-GroupProvideroutputs more than one value in one call. A stray value (anArrayList.Addindex, say) or a list returned without the leading comma is still taken as part of one group, as before, but now with a warning once per run that says how many values arrived. Discard a stray value with$null = ..., and return a list group asreturn ,$list. (#105)
Documentation
- Limits now says what a locked-down machine sees when the kit loads. On Windows PowerShell 5.1 the compile writes a few temporary files to
%TEMP%and deletes them during the load, and with no logging policy set, PowerShell records every load as a Warning-level script block logging event (4104), on 5.1 and 7. (#110)
v4.0
ParallelKit 4.0
After updating, start a new PowerShell window. The kit's compiled parts changed, so a session that loaded an older copy will refuse to load this one.
The kit can now be built as a PowerShell module, imported with Import-Module in place of dot-sourcing the file. Before that, 4.0 settles its names: Invoke-PkRunspaceJobs is now Invoke-PkRunspaceBatch, the batch and dispatch engines all take -MaxConcurrent and -AbortTimeoutSeconds, and parameters kept only for old scripts are gone. A batch now works when the kit's functions aren't global, and the worker-safety check catches more scriptblocks handed to .NET. Several of these changes can break an existing script, so read "Upgrading" first.
Upgrading from 3.5
Set-PkMessageHandlerthrows in worker code. The handler a worker set was its own runspace's scriptblock, which the main thread then ran, and that can hang or crash. Set it on the main thread before starting the workers;Write-PkMessagein a worker already goes to it. (#95)Invoke-PkProcessWithTimeoutthrows instead of starting its program while an abort or cancel is in force. A quick program used to run anyway. A cleanup program that has to run then needs-IgnoreAbort: in-JobAbortCleanup, say, or after an abortedInvoke-PkRun, since an abort stays in force untilReset-PkAbortState. (#96)Invoke-PkRunspaceBatchrefuses a worker that passes a wrapped scriptblock to a .NET method or constructor: in parentheses, cast to[scriptblock], or with.GetNewClosure(), in the call or through a variable. .NET turns it into a delegate, which can hang or crash a worker. Put# pk:ignoreon the line if the method really takes a scriptblock. (#97)Invoke-PkRunspaceJobsis nowInvoke-PkRunspaceBatch. Nothing else about it changes but the two parameter names below. The old name is gone. (#98)-MaxConcurrentand-AbortTimeoutSecondsare the only names for the limits. OnInvoke-PkProcessBatch,Invoke-PkProcessDispatchandInvoke-PkRunspaceBatch, replace-MaxParallelwith-MaxConcurrent, and-DrainTimeoutSecondswith-AbortTimeoutSeconds. (#98)Initialize-ParallelKithas no-MaxConcurrentProcessesand noThreadPoolin its result. Both have done nothing since 3.4. Take the parameter off your call; don't check the field. (#99)- The dispatcher's
-AbortPollCallbackis gone. Use-PollCallback, its name since 3.0. (#99)
Fixed
Invoke-PkProcessBatchworks when the kit's functions aren't global. Loaded for one module only, every batch failed with "'Complete-PkProcess' is not recognized". A.GetNewClosure()callback of your own still needs the functions it calls to be global. (#94)Invoke-PkProcessWithTimeoutno longer starts a program during an abort or cancel. A quick one ran to the end, and a slower one for about 200 ms before it was killed. (#96)- The
DelegateCastcheck sees a scriptblock through parentheses, a[scriptblock]cast or.GetNewClosure().[System.Threading.Tasks.Task]::Run({ 1 }.GetNewClosure())in a worker wasn't flagged. (#97) - Loading the kit over a newer version's compiled parts says so. The message said an "older version" was loaded; it's "a different version" now. (#99)
Added
- The kit as a PowerShell module, on the PowerShell Gallery:
Install-Module ParallelKit -Scope CurrentUser. It's the same code asParallelKit.ps1, imported withImport-Modulein place of dot-sourcing, andBuild/New-ParallelKitModule.ps1builds it from a copy of the repository. The README's new "As a module" section says how it differs: a refused import doesn't stop your script by itself, and a module of yours that uses the kit lists it inRequiredModulesor imports it with-Global. The module's version has three parts:Get-Moduleshows this release as 4.0.0. (#100, #102, #103)
v3.5
ParallelKit 3.5
After updating, start a new PowerShell window. The kit's compiled parts changed, so a session that loaded an older copy will refuse to load this one.
Programs the kit starts now get an empty stdin instead of PowerShell's own, so one that reads its input can't take what was meant for your script or wait for it forever; -InheritStdin gives the old behavior back. -KillTreeOnExit is new: it kills whatever a program left running when it exits. And a worker that reads a variable it never declares, such as one a .GetNewClosure() captured, is refused with a message instead of reading it as empty. The stdin and worker changes can affect an existing script, so read "Upgrading" first.
Upgrading from 3.4
- Programs no longer inherit PowerShell's stdin; theirs is empty. A program that reads its input gets the end of it at once, instead of taking input meant for your script or waiting for it. If a program needs the input your script was given, use
-InheritStdin(new in this release).timeout.exerefuses to run with empty input ("Input redirection is not supported"), socmd /c timeout /t 5as a delay fails at once now: useping -n 6 127.0.0.1 >nulinstead.-InheritStdinbringstimeout.exeback only if your script's own stdin is a console. (#86) - The batch and the dispatcher's default starter read an
InheritStdinkey on each command or job:$trueor$false. Don't use that name for a field of your own; another value there is a failed start. (#86) - The dispatcher uses one more key on each job,
KillTree, and it and the batch read aKillTreeOnExitkey:$trueor$false. Don't use those names for fields of your own; another value ofKillTreeOnExitis a failed start. (#87) Invoke-PkRunspaceJobsrefuses a worker that reads a variable it never declares or assigns. Such a variable (one of your script's, or one a.GetNewClosure()captured) read as empty in the worker, with no error. Pass it as a job value instead. If something the worker runs sets it (a helper file it dot-sources, a module it imports), put# pk:ignoreon the line that reads it.$global:names, drive-qualified ones ($env:) and shared functions aren't checked. (#89)
Fixed
- A program that reads its input no longer takes your script's, or hangs waiting for it. With a script run as
type list.txt | powershell -File script.ps1, a program the kit started could read from that list; one that waited for input sat until its time limit, or forever without one. (#86) Invoke-PkRunspaceJobsstarts faster on Windows PowerShell 5.1 when its worker calls functions from installed modules (Get-FileHash, say). The check it makes first searched all ofPSModulePathon every call; now each module is looked up once per session. With 154 modules installed, a one-job run went from 47 ms to 23 ms. A module the kit didn't find, and that you then install, is only seen in a new window. (#88)- A worker made with
.GetNewClosure()no longer loses its variables without a word.{ param($Id) "[$prefix$Id]" }.GetNewClosure()returned[1]in a worker, whatever$prefixwas. The run is now refused, and the message says to pass the variable as a job value. (#89) - The README says which programs get a batch file's
%*, or a list passed throughcmd.exe /c, back wrong: ones built against the oldmsvcrt.dllruntime, as most MinGW builds are, when an element holds a". It also says that a program can't start a child outside the kit's Job Object. (#90, #91)
Added
-InheritStdinonStart-PkProcess,Invoke-PkProcessWithTimeout,Invoke-PkProcessBatchandInvoke-PkProcessDispatch: give programs PowerShell's own stdin, as before 3.5. A command's or job's ownInheritStdinkey,$trueor$false, overrides it either way. (#86)-KillTreeOnExitonInvoke-PkProcessWithTimeout,Invoke-PkProcessBatchandInvoke-PkProcessDispatch: when a program exits, kill whatever it started that's still running, so nothing it left behind can hold its output open until-StreamTimeoutMs. A command's or job's ownKillTreeOnExitkey,$trueor$false, overrides it either way. Off by default, since some tools leave a build server or a daemon running on purpose. It needs the program to have a Job Object of its own, the normal case; one without is left alone. With your own-JobPollCompleted, the kill happens inComplete-PkProcess. (#87)Test-PkWorkerSafetyhas a new finding,UndeclaredVariable, for the rule above. It names the variable and the line. (#89)
v3.4.1
ParallelKit 3.4.1
After updating, start a new PowerShell window. The kit's compiled parts changed, so a session that loaded an older copy will refuse to load this one.
A fix release: two cases where programs could run without cleanup if PowerShell was killed, and the kit said nothing, now warn. No parameters or result fields change.
Fixed
- A Job Object that couldn't be set up is reported however the kit was started. A script that started programs without calling
Initialize-ParallelKitorInvoke-PkRunfirst got no warning when Windows refused the kit a Job Object, though the README says it warns: its programs ran with no cleanup if PowerShell was killed. It now warns once, asInitialize-ParallelKitdoes. (#83) - A running program Windows won't add to the Job Object is reported. Where the kit starts a program and adds it to the Job Object just after (
StartModeAddedToJob), a refusal was ignored, and that program ran on with no cleanup if PowerShell was killed. The kit now warns once, naming the process and why. A program that has already exited by then, which Windows also refuses, doesn't count. (#83)
v3.4
ParallelKit 3.4
After updating, start a new PowerShell window. The kit's compiled parts changed, so a session that loaded an older copy will refuse to load this one.
This release is about what happens when a program leaves something running that holds its output open. That no longer makes new programs lose their output, stalls the whole batch or dispatcher, or piles up output nobody can get in memory, and a kill now takes everything the program started, even a helper whose parent has already exited. Two new parameters: -StreamTimeoutMs on the batch and dispatcher sets how long to wait for held output, and -MaxOutputChars caps how much of a program's output is kept. The kit also leaves the thread pool's settings alone now, refuses runspace jobs that leave out a mandatory worker parameter before anything starts, and takes a code page given as a string. A few of these changes can affect existing scripts, so check "Upgrading from 3.3" before you update.
Upgrading from 3.3
- A kill now takes everything the program started, including what it left running on its own. A time-limit kill, an abort's force-stop and
Stop-PkProcessTreeused to miss a program's descendant whose parent had already exited (astart /bhelper, say); it ran on until PowerShell exited. If a program you run on a time limit deliberately launches something meant to outlive it, that now goes too. A program that exits on its own still leaves what it started running, as before. (#77) - The kit no longer raises the thread pool's minimum.
Initialize-ParallelKit, the first program started and eachInvoke-PkProcessDispatchused to raise it to at least 128 worker threads, a setting your own code shares; output reads have threads of their own since this release, so the kit doesn't need it. If your own code relied on that, raise it yourself with[System.Threading.ThreadPool]::SetMinThreads.Initialize-ParallelKitstill returnsThreadPool(always$true) and still accepts-MaxConcurrentProcesses, which does nothing now. (#76) - Results have two more fields at the end,
StdoutDroppedCharsandStderrDroppedChars(0 unless-MaxOutputCharsis set), onComplete-PkProcess,Invoke-PkProcessWithTimeoutand each batch result. They show up as new columns inFormat-Table,Export-Csvand JSON. (#75) - What a stream timeout hands over is that stream's text from then on. The read of a held stream still goes on until the program holding it lets go, but drops what it reads. So a second
Complete-PkProcesson the same job returns the same text as the first, not what arrived since, and so does the read task'sResultonce the stream ends. (#70) StreamErrorgives the failed read's own reason, not PowerShell's "Exception calling "WaitAll" ... One or more errors occurred" wrapper. A script that matched on that text needs to change. (#70)- With the dispatcher's default
-JobPollCompleted, a job finishes once its output has been read, or 15 seconds after its program exited if something holds the output open, instead of as soon as the program exits. The job keeps its slot meanwhile. A-JobFinalizethat passesComplete-PkProcessa shorter-StreamTimeoutMs, 0 included, no longer gets its result sooner: the wait has already happened, so set the dispatcher's own-StreamTimeoutMsinstead (new in this release). A longer one still waits the rest. (#71, #74) - The dispatcher uses three more keys on each job,
OutputWait,OutputWaitOverandOutputWaitMs. Don't use those names for fields of your own. (#71, #74) Invoke-PkRunspaceJobsrefuses a job that leaves out a mandatory worker parameter. A job missing a[Parameter(Mandatory)]parameter used to fail on its own and land inErrorswhile the rest ran. Now a fixed-JobParamslist is refused before anything starts ("Nothing was started"), and a-NextJobProviderjob stops the run when it arrives, as a key the worker doesn't declare already did.CancelTokenis exempt, since it's filled in, and so are workers with parameter sets. (#72)
Added
-StreamTimeoutMsonInvoke-PkProcessBatchandInvoke-PkProcessDispatch: how long to wait for a program's output after it exits when something it started holds the output open (default 15000 ms, as before; 0 doesn't wait). In the dispatcher, aComplete-PkProcessin-JobFinalizewith no-StreamTimeoutMsof its own uses it. (#74)-MaxOutputCharsonStart-PkProcess,Invoke-PkProcessWithTimeout,Invoke-PkProcessBatchandInvoke-PkProcessDispatch: keep at most that many characters of each output stream, so a program that prints gigabytes doesn't fill memory. Past the cap, the first half and the last half are kept, and the new result fieldsStdoutDroppedCharsandStderrDroppedCharssay how many characters were left out. The rest is still read, so the program never stalls on a full pipe. A command's or job's ownMaxOutputCharskey overrides it. The default, 0, keeps everything, as before. (#75)
Fixed
- Programs left holding their output no longer make new programs lose theirs. Each output read used a thread-pool thread until its stream closed, so once leftover programs (from a
cmd /c start /b ..., say) holding their output open had used up the pool's minimum (128 threads by default, two per program), a new program's output came back empty withStreamTimedOut, even a plainecho. Each read now has a thread of its own: a held stream costs one thread until the program holding it lets go, and other programs' output isn't held up. 3.2 and 3.3 both had this. (#69) - Output written after a stream timeout no longer piles up in memory. A program that kept writing to a held stream after the result was handed over had all of it kept, though nobody could get it: 60 MB written after the timeout took PowerShell's managed memory from about 9 MB to 127 MB until the writer let go. Now that output is read and dropped. (#70)
- A read that fails while the other stream is held open is reported. The result used to show only
StreamTimedOut, withStreamErrorempty and the failed stream$nullfor no visible reason.StreamErrornow has the reason in that case too. (#70) - A finished program's output pipes are closed when its output ends, rather than at the next garbage collection. (#70)
- One program's held output no longer stalls the whole batch or dispatcher. The wait for it (up to 15 seconds) ran on the dispatch loop's own thread, so no other program was started, finished, killed at its time limit or stopped by an abort meanwhile: a program with a 2 second limit next to one whose output was held for 6 seconds was killed at 6 seconds. The wait now runs alongside the other jobs. After an abort's wait, a program that had already finished keeps the output that arrived, instead of being force-stopped and reported as aborted. (#71)
- The text a stream timeout hands over never ends in half of a two-part character. With UTF-16 output (
cmd /u, say), an emoji read half before the timeout used to come back as a lone first half; it's now left out. (#75) - A kill no longer leaves behind what the program started through a step that has already exited. Each program the kit starts now has a Job Object of its own, so a time-limit kill, an abort's force-stop and
Stop-PkProcessTreeend its whole tree at once, including astart /bhelper whose parent is gone, whichtaskkill /Tcouldn't find. Such a helper used to keep running, and if it held the program's output, the job waited another 15 seconds after the kill: a command with a 2 second limit took 17 seconds. (#77) -OutputEncodingtakes a code page given as a string, such as'65001'read from a CSV or a config file, or as the Int64ConvertFrom-Jsongives on PowerShell 7. Both used to be refused with a message that said to use 65001. (#72)
v3.3
ParallelKit 3.3
After updating, start a new PowerShell window. The kit's compiled parts changed, so a session that loaded an older copy will refuse to load this one.
This release fixes a dispatcher run that could go on forever, keeps output that a leftover program held open instead of losing it, and makes sure killing thousands of programs at once kills their children too. Time limits that can't work are now refused up front. It also adds a Duration field to process results, and Version and StartMode to Initialize-ParallelKit. A few of these changes can affect existing scripts, so check "Upgrading from 3.2" before you update.
Upgrading from 3.2
-
Time limits that can't work are refused up front. These now stop the call with an error naming the parameter:
-TimeoutSecondsof NaN or infinity onInvoke-PkProcessBatchandInvoke-PkProcessDispatch, which acted as no limit.- A negative
-StreamTimeoutMs,Wait-PkProcess -TimeoutMs,-AbortTimeoutSecondsor-DrainTimeoutSeconds. -1 waited without limit; other negative values failed later or acted as 0.
0 means what it did before. (#63)
-
-NextJobProvidergoes by its last value. If a call's output ends in$null, the run ends, even when a job hashtable came before it (that job used to run). Of two job hashtables, the last one runs, as before, but the first is now warned about. (#62) -
-GroupProvideroutput that ends in$nullends the groups, with a warning. That includes a list given as one group whose last item is$null, because it can't be told apart from a stray value followed byreturn $null. (#62) -
A stream that timed out now has its text, not
$null. A script that checkedStdoutorStderrfor$nullto spot a stream timeout should checkStreamTimedOutinstead. (#66) -
Process results have a new
Durationfield, andInitialize-ParallelKithasVersionandStartMode, so aFormat-Tableof either shows more columns. (#65, #67)
Fixed
- A
-GroupProviderthat let a value out beforereturn $nullnever finished.$log.Add('asked'); return $nullreached the dispatcher as one more group, so it asked again forever. That output now ends the groups, with a warning. (#62) - Output held open by a leftover program is cut short, not lost. When a program started by your program (a compiler server, say) kept stdout or stderr open past the stream timeout, that stream came back empty, so a build step whose helper outlived it lost its whole log. Each stream now comes back with what arrived before the timeout, and
StreamTimedOutstill says it was cut short. (#66) - Killing thousands of programs at once could leave their children running. The tree kill passed every program to one
taskkillcall. Windows refuses that call past about 2,500-3,000 programs, and the fallback then killed only the programs themselves. It now uses as manytaskkillcalls as needed. Ataskkillthat hangs is now killed instead of being left running. (#64) - A
-GroupReleaseCheckthat let a value out could release a held group early.$log.Add($g); return $falsewas read as true. Only the check's last value counts now, as with-JobPollCompleted. (#62)
Added
-
Durationon process results: how long each program ran, from its start to its exit or kill, as a[TimeSpan]. It doesn't include time spent waiting for a slot, or waiting for its output afterwards. It's onInvoke-PkProcessBatch's results and onInvoke-PkProcessWithTimeout's andComplete-PkProcess's result, and it's$nullfor a command that never started.$batch.Results | Sort-Object Duration -Descendingfinds the slow ones. (#67) -
Initialize-ParallelKitreportsVersionandStartMode.StartModesays how the kit starts programs in this session:CreatedInJob: inside the Job Object, the normal case.AddedToJob: started, then added to the Job Object just after.NoJob: no cleanup if PowerShell is killed.
The README's "Bugs and questions" now asks for
Initialize-ParallelKit's output in an issue. (#65) -
A warning when the kit can't create programs inside the Job Object. This relies on a private part of .NET. When it wasn't available, the kit silently fell back to starting the program and adding it to the Job Object just after, and a child the program starts in that moment can escape the cleanup. The kit now warns once when it falls back. It also falls back now when setting up a start fails, where 3.2 reported that the program couldn't start. (#65)
v3.2
ParallelKit 3.2
After updating, start a new PowerShell window. The kit's compiled parts changed, so a session that loaded an older copy will refuse to load this one.
This release closes the last gap in "No orphans": a program the kit starts can no longer slip a child process past its Job Object. It has two small changes that can affect existing scripts. Check "Upgrading from 3.1" before you update.
Upgrading from 3.1
$job['Proc']'s ownStandardOutput,StandardErrorandStartInfoare no longer set.Procis still the program'sProcess, andHasExited,ExitCode,WaitForExit,KillandDisposework as before. Read output fromStdoutTaskandStderrTask, as the docs already say. (#56)- A start error has shorter text. It now gives Windows' reason, such as "The system cannot find the file specified", without PowerShell's
Exception calling "Start" with "1" argument(s):wrapper. Anything that matches on the old text needs updating. The error itself, and Windows' error code inside it, are unchanged. (#56)
Fixed
- A child process started straight away could survive the script being killed outright. The kit added each program to its Job Object just after starting it, so with
cmd /c tool.exe,tool.execould already be running outside it, and kept running if the script was killed from Task Manager. Each program is now created inside the Job Object, so everything it starts is killed with the script. Ctrl+C, aborts and timeouts were never affected. This removes the note about it under Limits. (#56)
v3.1
ParallelKit 3.1
After updating, start a new PowerShell window, so nothing from the older copy is left in your session.
This release fixes the dispatcher's force-stop and finalize steps, closes a quoting gap for cmd.exe itself, and has three changes that can affect existing scripts. Check "Upgrading from 3.0" before you update.
Upgrading from 3.0
cmd.exegiven a list gets the same quoting as a.bator.cmdprogram. WhenFilePathiscmdorcmd.exe(any folder) andArgumentsis a list, a quote inside an element is now written""instead of\", and an element with a line break is an error. Ordinary/clists, with spaces, quotes or trailing backslashes, still reach the program after/cas given. (#51)- Only the last value a
-JobPollCompletedoutputs counts. If your poll writes its answer and then something else, put the answer last or send the rest to$null. (#49) Invoke-PkProcessWithTimeoutrefuses a-TimeoutMsbelow 1. It used to start the program and kill it at once. (#50)
Security
- A list in
Argumentscan no longer makecmd.exerun another command when the program iscmd.exeitself (FilePath = 'cmd.exe',Arguments = @('/d', '/c', 'tool.exe', $file)). 3.0 closed this for.batand.cmdprograms only, so an element holding a quote, such as an untrusted value likea" & del ... & ", could still end the quoting and run what followed. (#51) - A batch file that reads its argument as
%~1undoes the kit's quoting.%~1strips the quotes, so a value likea & echo INJECTEDruns as a command inside the batch file. That happens in your batch file, outside the kit's control: write"%~1"(or%1) there. The README now says so. (#45)
Fixed
- Stopping about 20 or more running programs at once took 10 seconds and could leave some of their child processes running. This hit an abort's force-stop and the cleanup after an error. (#46)
- A
-JobFinalizethat disposed its job's process and then threw left every other running job's child processes running. They're now killed, as when any other callback throws. (#47) - When
-JobFinalizethrew,-JobAbortCleanupwas also called for the job it was finalizing, although that job had finished. A cleanup that deletes partial output could delete its real output. Now only jobs the kit kills or never starts get the cleanup. (#48) - A
-JobPollCompletedthat wrote a stray value before its answer (anArrayList.Addindex, say) made a running job look done, so it was finalized and its process disposed while the program still ran. (#49)
Documentation
- A program with spaces in its path, run through
cmd.exe /c, needs the one-string form.cmd.exestrips the quotes from it whatever the quoting, so give it'/d /s /c ""C:\My Tools\tool.exe" "a b""'. This isn't new in 3.1; the README now spells it out. (#51) - A program started in its parent's first moment (
tool.exeundercmd /c tool.exe) can miss the kit's Job Object, and then survives the script being killed outright. It's rare, and Ctrl+C, aborts and timeouts aren't affected. See Limits in the README. (#52) Invoke-PkRunspaceJobs'-Ctshelp now says the kit also cancels your source when it exits with workers still running (one of your callbacks threw, say), not only on an abort. (#53)