From e537acf404a2c4846469cf59acdd461a49c4c3c1 Mon Sep 17 00:00:00 2001 From: Guilherme Lawless Date: Fri, 17 May 2019 18:59:27 +0100 Subject: [PATCH] Suppress panicking when pipe closed --- src/gpu.rs | 2 +- src/main.rs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/gpu.rs b/src/gpu.rs index 99bc5eb..2ea071f 100644 --- a/src/gpu.rs +++ b/src/gpu.rs @@ -39,7 +39,7 @@ impl Gpu { .build()?; let device = pro_que.device(); - eprintln!( + println!( "Initializing GPU: {} {}", device.vendor().unwrap_or_else(|_| "[unknown]".into()), device.name().unwrap_or_else(|_| "[unknown]".into()) diff --git a/src/main.rs b/src/main.rs index db69694..0cbd979 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,6 +14,7 @@ extern crate serde_json; mod gpu; +use std::io::{self, Write}; use std::u64; use std::num::Wrapping; use std::collections::VecDeque; @@ -274,9 +275,10 @@ impl RpcService { Box::new(self.generate_work(root, difficulty).then(move |res| match res { Ok(work) => { let end = PreciseTime::now(); - println!("work_generate completed in {}ms for difficulty {:#x}", + writeln!(io::stdout(), "work_generate completed in {}ms for difficulty {:#x}", start.to(end).num_milliseconds(), - difficulty); + difficulty) + .unwrap_or(()); let result_difficulty = work_value(root, work); Ok(( StatusCode::Ok, @@ -302,12 +304,12 @@ impl RpcService { })) } RpcCommand::WorkCancel(root) => { - println!("Received work_cancel"); + writeln!(io::stdout(), "Received work_cancel").unwrap_or(()); self.cancel_work(root); Box::new(Box::new(future::ok((StatusCode::Ok, json!({}))))) } RpcCommand::WorkValidate(root, work, difficulty) => { - println!("Received work_validate"); + writeln!(io::stdout(), "Received work_validate").unwrap_or(()); let (valid, result_difficulty) = work_valid(root, work, difficulty); Box::new(future::ok(( StatusCode::Ok,