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

Exec Stream never ends #330

Open
chillcaw opened this issue Jul 26, 2023 · 0 comments
Open

Exec Stream never ends #330

chillcaw opened this issue Jul 26, 2023 · 0 comments

Comments

@chillcaw
Copy link

Background

Not sure if this a bug or I'm missing something here.

I'm copying a python file over and running it, but the Stream from Container::exec never seems to return None. When I run through docker exec it'll run once and exit.

# sample.py
my_var = 123
print(my_var)
print(124)
print(125)
print(126)
// main.rs
#[tokio::main]
async fn main() {
    
    // There is more code here, but it all works so far
    // ...

    println!("Running Exec");

    let options = ExecContainerOptions::builder()
        .cmd(vec!["python", "/opt/sample.py"])
        .attach_stdout(true)
        .attach_stderr(true)
        .build();

    while let Some(exec_result) = docker
        .containers()
        .get(&container_id)
        .exec(&options)
        .next()
        .await
    {
        match exec_result {
            Ok(chunk) => {
                print_chunk(chunk);
            }
            Err(e) => eprintln!("Error: {}", e),
        }
    }
}

fn print_chunk(chunk: TtyChunk) {
    match chunk {
        TtyChunk::StdOut(bytes) => println!("Stdout: {}", from_utf8(&bytes).unwrap()),
        TtyChunk::StdErr(bytes) => eprintln!("Stdout: {}", from_utf8(&bytes).unwrap()),
        TtyChunk::StdIn(_) => unreachable!(),
    }
}

Output:

Stdout: 123
124
125
126

Stdout: 123
124
125
126

Stdout: 123
124
125
126

Stdout: 123
124
125
126

Stdout: 123
124
125
126

Stdout: 123
124
125
126

Stdout: 123
124
125
126

Stdout: 123
124
125
126

..... forever
  • Crate version: master
  • OS: Window 10
  • Output of running docker version on the command line: 24.0.2
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

No branches or pull requests

1 participant