Skip to content
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

feat(python): streaming bin script output #3794

Merged
merged 11 commits into from
Nov 23, 2022

Conversation

jmalins
Copy link
Contributor

@jmalins jmalins commented Oct 6, 2022

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.

@jmalins
Copy link
Contributor Author

jmalins commented Oct 6, 2022

Note, the kernel recording tests needed to be disabled for the getBinScriptCommand method since the output is not deterministic due to the tarball extraction directory being different between runs. This method is tested in the Python runtime tests, so there should be reasonable assurance it is works.

@jmalins
Copy link
Contributor Author

jmalins commented Oct 10, 2022

@RomainMuller, are there any changes you'd recommend to this PR?

packages/@jsii/kernel/src/kernel.test.ts Outdated Show resolved Hide resolved
packages/@jsii/kernel/src/kernel.ts Outdated Show resolved Hide resolved
}

return {
command: path.join(packageDir, scriptPath),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, this may only work if the caller spawns that commend via a shell, which is a relatively easy way to inadvertently make your code not work on Windows...

There would be a .cmd file that might be preferable to use as an entry point when on Windows if present...

Copy link
Contributor Author

@jmalins jmalins Nov 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't disagree. I was taking a "do no harm" approach with this PR by just carrying forward the existing logic, which would also not work on Windows.

I don't have easy access to a Windows host to test and understand the auto-generated .cmd file mentioned here: https://docs.npmjs.com/cli/v9/configuring-npm/package-json#bin

Is it essential that Windows support be included in the PR, since this isn't a new regression?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it essential that Windows support be included in the PR, since this isn't a new regression?

Well... no. I have this principle that I never demand contributors leave the place cleaner than they found it 😅

Comment on lines +1335 to +1336
// Make sure the current NODE_OPTIONS are honored if we shell out to node
NODE_OPTIONS: process.execArgv.join(' '),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not everything in process.execArgv is guaranteed to be valid to use in NODE_OPTIONS... That'll be randomly problematic in certain environments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above, this is a direct port of the existing invokeBinScript logic.

I think, in this case, the contents of process.execArgv is predictable because the JSII runtime spawns the node process. Python is currently the only runtime with bin script support and it appears to only pass --max-old-space-size=4069, which shouldn't present a problem:
https://github.com/aws/jsii/blob/main/packages/%40jsii/python-runtime/src/jsii/_kernel/providers/process.py#L252

jmalins and others added 5 commits November 15, 2022 08:20
Accept typing simplication

Co-authored-by: Romain Marcadier <romain.muller@telecomnancy.net>
Single error message for missing and/or no scripts defined.

Co-authored-by: Romain Marcadier <romain.muller@telecomnancy.net>
@jmalins
Copy link
Contributor Author

jmalins commented Nov 15, 2022

Hi @RomainMuller,
Flaky tests aside (two Maven download failures in a row), please let me know what else you'd require to merge this PR.

Thanks

@RomainMuller
Copy link
Contributor

two Maven download failures in a row

I see you have become acquainted with one of the pains of my life! 🤣

@mergify
Copy link
Contributor

mergify bot commented Nov 23, 2022

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Nov 23, 2022
@mergify
Copy link
Contributor

mergify bot commented Nov 23, 2022

Merging (with squash)...

@RomainMuller
Copy link
Contributor

@all-contributors add @jmalins for code

@allcontributors
Copy link
Contributor

@RomainMuller

@jmalins already contributed before to code

@mergify mergify bot merged commit 7a41349 into aws:main Nov 23, 2022
@mergify
Copy link
Contributor

mergify bot commented Nov 23, 2022

Merging (with squash)...

@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Streaming bin script output in non-typescript kernels
2 participants