-
Notifications
You must be signed in to change notification settings - Fork 245
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
Streaming bin script output in non-typescript kernels #3782
Comments
I wonder if we should reverse control here, and instead of having the kernel spawn the child process on behalf of the caller, it merely returned the As you're guessing, the IPC situation in Windows versus POSIX platforms is quite complicated, and it turns out to be relatively easy to introduce subtle bugs when attempting to do this (even |
@RomainMuller that is a profoundly better approach! 👍 How about this for an API, reusing the // api.ts
export interface GetScriptCommandResponse {
command: string;
args: string[];
env: Record<string, string>;
}
// kernel.ts
export class Kernel {
// ...
public getBinScriptCommand(req: api.InvokeScriptRequest): api.GetScriptCommandResponse;
// ...
} I presume we would retain the existing invoke API for compatibility purposes. It can be refactored to use the new |
I realized after getting into the code, that JSII requires a unique argument type for each API call. PR #3794 uses the basic approach above, but with a |
Resolves #3782. Inverts control on bin script execution by returning the script to execute (as well as arguments and ENV variables), rather than running it within the kernel process. This allows the calling process to pipe the output streams, rather than the kernel buffering the output and returning it at the end of the synchronous call. Also, adds more complete tests to the python runtime to validate `stderr`, exit codes and streaming response. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
|
Describe the feature
Pipe the output streams of bin scripts invoked from the JSII kernel. Currently, these calls are made using the synchronous
InvokeScriptRequest
/InvokeScriptResponse
synchronous API. The output is buffered until the call completes. This experience is not ideal for longer running scripts with progressive updates.Use Case
Long-running scripts with progressive updates, such as
projen deploy
called under Python via the JSII kernel, rather than a globally installed installedprojen
instance.These calls were recently made to work via a few updates:
The experience, however, is not ideal, due to the buffered output.
Proposed Solution
Maintain the current synchronous (
InvokeScriptRequest
/InvokeScriptResponse
) API for backwards compatibility, but add a new streaming API that language runtimes can opt into if they are on a platform that supports it. The opt-in approach will allow this to be implemented progressively.I suspect this will require out-of-band IPC (local domain sockets or named pipes) so that it doesn't disrupt the standard kernel connection streams.
I am not an IPC expert, but one (naive) approach on POSIX OSs would be:
stdout
andstderr
InvokeScriptWithStreams
callspawnSync
of the target processstdout
/stderr
on the user processInvokeScriptResponse
structureI have a nervous suspicion it is more complicated than this (
termcap
?), and I wouldn't know where to start with Windows. I definitely welcome thoughts on the approach.Other Information
My team is very interested in building out a first-rate Python dev-tool experience for JSII based libraries, specifically CDK on projen.
Acknowledgements
CDK version used
2.x
Environment details (OS name and version, etc.)
MacOS, Linux
The text was updated successfully, but these errors were encountered: