-
Notifications
You must be signed in to change notification settings - Fork 7.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow user code to stop a pipeline on demand / to terminate upstream cmdlets. #3821
Comments
There is a good detailed blog post on how to implement this in PowerShell today: Cancelling a Pipeline. I think it would be useful to implement something like as a built-in cmdlet. |
Thanks, @dragonwolf83; the blog post's author, Tobias Weltner, is the same person who created the linked uservoice.com issue; the blog post elicited the following @jpsnover response (dated "over 7 years ago"):
That's one lofty bar! :) |
Things that don't necessarily align with the PowerShell Team's priorities (which is not static) can still get done if contributed by the community :) |
We need RFC for new cmdlet and examples of how to use the cmdlet. |
Does anyone have a working link to Tobias' blog post mentioned above? That link seems to be dead. |
Here‘s some material: http://www.powertheshell.com/stop_pipeline/ |
Adding My proposal: namespace System.Management.Automation
{
public abstract class PSCmdlet
{
+ [DoesNotReturn]
+ public void StopUpstreamCommands();
}
} If added this should be tested both for binary cmdlets ( |
WG-Engine discussed this today (6/23/2022). We agree that users should have access to this functionality in some way that is not exclusive to We need more investigation on whether this behaviour would be problematic to expose as a commonly usable API, and whether we should:
|
I went through every command that overrides Find-Type -Base System.Management.Automation.PSCmdlet |
Find-Type -Not -ImplementsInterface System.IDisposable |
Find-Member StopProcessing -Force -Declared |
ForEach-Object {
dnSpy.Console.exe $_.Module.Assembly.Location --md $_.MetadataToken --no-tokens |
bat --language cs --style 'grid,numbers,snip'
Read-Host -Prompt 'Press enter to continue'
} Of all of them I found only one command that is using I would recommend we just fix |
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
1 similar comment
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
The ability to stop a pipeline on demand is currently only available internally, as used by
Select-Object -First <n>
, for instance.To quote from this uservoice.com issue:
A real-world example.
Also note that there are two distinct ways to "stop" a pipeline:
End
blocks, as simulated by this command usingbreak
with a dummy loop to break out of:Note that without the final
Sort-Object -Descending
pipeline stage, you would see output, because the objects are being output in the%
script block as they're being received.This quiet termination of the entire pipeline is similar to a statement-terminating error that is silenced.
Select-Object -First <n>
does, for instance, giving downstream cmdlets a chance to run theirEnd
blocks.This scenario is about stopping further input, while still allowing remaining pipeline stages to finish their processing.
However, the fact that the upstream cmdlets do not also get to run their
End
blocks can be problematic, as that may be required for cleanup tasks: see #7930; PR #9900 would instead introduce acleanup
block to ensure cleanup even when stopped viaStopUpstreamCommandsException
.Originally reported for:
The text was updated successfully, but these errors were encountered: