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

printstd() does not lock stdout #117

Open
yongqli opened this issue Sep 18, 2019 · 2 comments
Open

printstd() does not lock stdout #117

yongqli opened this issue Sep 18, 2019 · 2 comments
Labels

Comments

@yongqli
Copy link

yongqli commented Sep 18, 2019

The program below produces garbled output:

main.rs:

use prettytable::{Table, format, cell, row};

fn print_table(s: usize) {
    let mut table = Table::new();
    table.set_titles(row![c => "num"]);
    table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
    for i in s..s+100 {
        table.add_row(row![i]);
    }
    table.printstd();
}

fn main() {
    rayon::join(|| print_table(0), || print_table(1000));
}

Cargo.toml:

[package]
name = "prettytabletest"
version = "0.1.0"
edition = "2018"

[dependencies]
prettytable-rs = "*"
rayon = "1.0"
@dfirence
Copy link

Same issue here, when I pipe to less, or `more

Any update here?

@yongqli
Copy link
Author

yongqli commented Aug 31, 2020

I have found a workaround: you can lock stdout before calling printstd() because the lock is reentrant in practice, although it is not documented. I created an extension method printstdlocked(&self) which calls std::io::stdout().lock() before calling self.printstd();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants