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

Change container's exec_run function to return tuple of (function that returns exit_code, output) when stream/socket=True #2963

Closed
wants to merge 1 commit into from

Conversation

tzah4748
Copy link

@tzah4748 tzah4748 commented Mar 4, 2022

Inspired by: #2557

As explained in issue above, getting the exit code might be needed even when running with socket or stream set to True.
This can be easily achieved by returning a function that returns that exit code.

A simple use case:

async def _log_exec_result(exec_result: ExecResult):
    generator: Iterable = exec_result.output
    while exec_result.exit_code() is None:
        # Program still running
        output = next(generator, None)  # Assuming the generator has no None values
        if output is not None:
            # print/log
        else:
            # some sleep or w/e

exec_result = my_container.exec_run('/run/server/that/shows/requests/output', stream=True)
_log_exec_result(exec_result)
# Freely continue the program while logging the server outputs.

Note the above assumes (this behaviour was tested) that the exit code returned is None until the executed command/program finishes.

Signed-off-by: Tzah Mazuz tmazuz@nvidia.com

@tzah4748 tzah4748 changed the title Change Container's exec_run method tuple: exit_code is now a callable that returns the exit code. Change container's exec_run function to return tuple of (function that returns exit_code, stream/socket). Mar 4, 2022
@tzah4748 tzah4748 changed the title Change container's exec_run function to return tuple of (function that returns exit_code, stream/socket). Change container's exec_run function to return tuple of (function that returns exit_code, output) when stream/socket=True Mar 4, 2022
Signed-off-by: Tzah Mazuz <tmazuz@nvidia.com>
This pull request was closed.
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.

None yet

1 participant