| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
There was a problem hiding this comment.
Since this performs the same function as Ctrl+C signal, why not just use that? I thought we were going to implement Ctrl+Break as it was implemented before (stops running pipeline and exits process).
If so then it seems we should call the break handler like this:
SpinUpBreakHandlerThread(true);
BTW the previous implementation (before changing it to break into debugger) was to make absolutely sure that the process ends. I don't think we need to be this draconian but this was how it was implemented before:
// The Big Red Button!
// check if we are in a pushed session
// if so exit out of it
if (ConsoleHost.SingletonInstance.IsRunspacePushed)
{
ConsoleHost.SingletonInstance.PopRunspace();
HandleBreak();
return true;
}
// Log all sqm data before we exit.
System.Management.Automation.Sqm.PSSQMAPI.LogAllDataSuppressExceptions();
ConsoleHost.SingletonInstance.shouldEndSession = true;
ConsoleHandle handle = ConsoleControl.GetActiveScreenBufferHandle();
ConsoleControl.WriteConsole(handle, "\n" + ConsoleHost.exitOnCtrlBreakMessage);
unchecked
{
Environment.Exit((int)ExitCodeCtrlBreak);
}
Sorry, something went wrong.
There was a problem hiding this comment.
Paul Higinbotham (@PaulHigin) because I launch powershell in its own process group, ctrl+C is implicitly disabled for the lauched process and its children (see Remarks section of CreateProcess). This allows parent applications like my own to better control the propogation of SIGINT signals and prevent ctrl+c from broadcasting to all processes in the console.
I'll change shouldEndSession to true. I was blindly looking to imitate ctrl+c but true does make more sense. Thanks for the above snippet of the former behavior. I was looking for the state before entering the debugger yesterday and couldn't find it in the history.
I think sticking with SpinUpBreakHandlerThread is likely the best pattern to follow now.
Sorry, something went wrong.
|
changed shouldEndSession to true |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
There was a problem hiding this comment.
Please use named parameters.
Sorry, something went wrong.
There was a problem hiding this comment.
Please use named parameters.
Sorry, something went wrong.
… break Signed-off-by: Matt Wrock <matt@mattwrock.com>
|
Aditya Patwardhan (@adityapatwardhan) for consistency, I added the named params to all calls to SpinUpBreakHandlerThread and not just my additions. |
Sorry, something went wrong.
|
Matt Wrock (@mwrock) I like this with named parameters much better. Thanks. |
Sorry, something went wrong.
|
Can we add tests? |
Sorry, something went wrong.
|
I took a quick look Ilya (@iSazonov) at the pester tests covering ConsoleHost. Creating tests around sending signals to the console is problematic because the spawned process needs to be created with the CREATE_NEW_PROCESS_GROUP flag. C#/Powershell's [Process]::Start API does not expose the passing of creation flags. Without its own process group, broadcasting a ctrl+break would be captured by pester and would terminate the tests. I could certainly adjust the ConsoleHost tests to leverage DllImport and call directly into CreateProcessW but thats a rather heavy handed call and requires setting up a bunch of structs to support the CreateProcessW args. So I'm gonna let that go here. I'm totally open to other suggestions though! |
Sorry, something went wrong.
|
I feel a test for this is unnecessary. |
Sorry, something went wrong.
|
I don't at all mean to be pushy, but would love to see this merged and included in the next release. |
Sorry, something went wrong.
|
Matt Wrock (@mwrock) Thank you for your contribution! |
Sorry, something went wrong.
if running noninteractively then do not break into debugger on ctrl +…
| Back | FazBrowse Home | New Git URL |
This addresses #4254 by mimicing ctrl+c behavior on ctrl+break signals when running under -NonInteractive. While the current ctrl+break behavior of starting a debugger is excellent for debugging scripts interactively, it may pose a dilemma when running scripts noninteractively. This is especially true, as discussed in #4254, if the scripts are managed by a parent application that wishes to signal spawned powershell processes to cease execution gracefully.
I have built this PR and run it in my process supervisor application validating that it has the desired effect of gracefully terminating the pipeline when recieving a ctrl+break from GenerateConsoleCtrlEvent to its process group.