-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Allow user code to stop a pipeline on demand / to terminate upstream cmdlets. #3821
Copy link
Copy link
Open
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeThe bot will ignore these and not auto-closeWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
Milestone
Metadata
Metadata
Assignees
Labels
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifIssue-Enhancementthe issue is more of a feature request than a bugthe issue is more of a feature request than a bugKeepOpenThe bot will ignore these and not auto-closeThe bot will ignore these and not auto-closeWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtimeWG-ReviewedA Working Group has reviewed this and made a recommendationA Working Group has reviewed this and made a recommendation
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:
Endblocks, as simulated by this command usingbreakwith a dummy loop to break out of:Note that without the final
Sort-Object -Descendingpipeline 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 theirEndblocks.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
Endblocks can be problematic, as that may be required for cleanup tasks: see #7930; PR #9900 would instead introduce acleanupblock to ensure cleanup even when stopped viaStopUpstreamCommandsException.Originally reported for: