-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add clean block to script block as a peer to begin, process, and end to allow easy resource cleanup
#15177
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
Add clean block to script block as a peer to begin, process, and end to allow easy resource cleanup
#15177
Conversation
990f70b to
6c3dd9c
Compare
6c3dd9c to
f2a9d87
Compare
This comment has been minimized.
This comment has been minimized.
It would be amazing for cmdlets to terminate whole script or process but acceptable for script blocks. |
e90ebbb to
3ba0c31
Compare
test/powershell/Language/Scripting/PipelineBehaviour.Tests.ps1.bak
Outdated
Show resolved
Hide resolved
test/powershell/Language/Scripting/PipelineBehaviour.Tests.ps1.bak
Outdated
Show resolved
Hide resolved
PaulHigin
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still reviewing, but submitting initial comments/questions.
src/System.Management.Automation/engine/CommandProcessorBase.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandProcessorBase.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandProcessorBase.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandProcessorBase.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandProcessorBase.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandProcessorBase.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandProcessorBase.cs
Outdated
Show resolved
Hide resolved
662159d to
88c8aa5
Compare
|
you suggest that errors in the clean block will be captured in |
Errors in
I personally prefer to not make the @JamesWTruher The proposed error handling behavior already works with the changes in this PR, so I think it will be helpful if you can build this PR and play with it. You can also download the build artifacts from CIs, for example, the windows build can be downloaded here. Thanks for the review and I look forward to get more feedback from you! |
src/System.Management.Automation/engine/CommandProcessorBase.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandProcessorBase.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/CommandProcessorBase.cs
Outdated
Show resolved
Hide resolved
src/System.Management.Automation/engine/hostifaces/LocalPipeline.cs
Outdated
Show resolved
Hide resolved
1. not support directly invoking the 'clean' block of a script block. 2. not support a script block with the 'clean' block for '.ForEach' magic method. 3. make 'clean' block mimic the 'finally' clause 4. add a few more tests
9359f12 to
93305d4
Compare
|
Rebased the commits to resolve conflicts introduced by #16199 |
|
SSH remoting test run was cancelled due to an issue in the test pipeline, which was fixed by #16225 |
|
🎉 Handy links: |
…d `end` to allow easy resource cleanup (PowerShell#15177)
This is an alternate implementation of the
Cleanblock in PowerShell. The original PR is #9900.This implementation doesn't rely on the
Disposemethod to run theCleanblock, but instead makesCleanblock more like a peer tobegin,process, andendblocks.The updated RFC is currently under review: PowerShell/PowerShell-RFC#294
The doc issue for this feature: MicrosoftDocs/PowerShell-Docs#8090
The editor syntax PR: PowerShell/EditorSyntax#208
To-do check list:
SynchronousExecutionEnumerateExitinCleanblock?Exitfrom within aCleanblock terminates the execution in theCleanblockExitExceptionis not propagated out of theCleanblockfinallybehavior *]cleanuptoclean{ clean { } }? Nocleanblock [manually checked]* The Ctrl+c behavior is still pending. The updated RFC discusses two different behaviors in the event of pipeline stopping in details in the
Pipeline Stopping Behaviorsection. The current implementation in this PR mimics thefinallyclause behavior, but it keeps the changes inStopperthat would be needed to support non-cancellablecleanblock execution.[Update 01/07/2025] The changes in
Stopperwas actually removed in the commit 0060e0d based on the conversation in #15177 (comment), because the decision was to follow thefinallybehavior in the event of pipeline stopping. The changes can be found in the abovementioned commit in case it's needed.