History

fix: Collect all stdout messages in line renderer as well (#215)

Otherwise the threaded line renderer will interfere with genuine program output.

Sebastian Thiel committed 4 years ago

Commit 57ca0451 parent e4514a81 file · +6 −4Browse files

Unified · Split

src/shared.rs+6−4
@@ -85,7 +85,7 @@ pub mod pretty { · 84 unmodified lines
85 enum Event<T> {85 enum Event<T> {
86 UiDone,86 UiDone,
87 ComputationFailed,87 ComputationFailed,
88 ComputationDone(Result<T>),88 ComputationDone(Result<T>, Vec<u8>),
89 }89 }
90 use crate::shared::{self, STANDARD_RANGE};90 use crate::shared::{self, STANDARD_RANGE};
91 let (tx, rx) = std::sync::mpsc::sync_channel::<Event<T>>(1);91 let (tx, rx) = std::sync::mpsc::sync_channel::<Event<T>>(1);
@@ -103,11 +103,12 @@ pub mod pretty { · 11 unmodified lines
103 // LIMITATION: This will hang if the thread panics as no message is send and the renderer thread will wait forever.103 // LIMITATION: This will hang if the thread panics as no message is send and the renderer thread will wait forever.
104 // `catch_unwind` can't be used as a parking lot mutex is not unwind safe, coming from prodash.104 // `catch_unwind` can't be used as a parking lot mutex is not unwind safe, coming from prodash.
105 let join_handle = std::thread::spawn(move || {105 let join_handle = std::thread::spawn(move || {
106 let mut out = Vec::<u8>::new();
106 let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {107 let res = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
107 run(Some(sub_progress), &mut stdout(), &mut stderr())108 run(Some(sub_progress), &mut out, &mut stderr())
108 }));109 }));
109 match res {110 match res {
110 Ok(res) => tx.send(Event::ComputationDone(res)).ok(),111 Ok(res) => tx.send(Event::ComputationDone(res, out)).ok(),
111 Err(err) => {112 Err(err) => {
112 tx.send(Event::ComputationFailed).ok();113 tx.send(Event::ComputationFailed).ok();
113 std::panic::resume_unwind(err)114 std::panic::resume_unwind(err)
@@ -120,9 +121,10 @@ pub mod pretty { · 6 unmodified lines
120 drop(join_handle);121 drop(join_handle);
121 Err(anyhow::anyhow!("Operation cancelled by user"))122 Err(anyhow::anyhow!("Operation cancelled by user"))
122 }123 }
123 Event::ComputationDone(res) => {124 Event::ComputationDone(res, out) => {
124 ui_handle.shutdown_and_wait();125 ui_handle.shutdown_and_wait();
125 join_handle.join().ok();126 join_handle.join().ok();
127 std::io::Write::write_all(&mut stdout(), &out)?;
126 res128 res
127 }129 }
128 Event::ComputationFailed => match join_handle.join() {130 Event::ComputationFailed => match join_handle.join() {