Add names to threads and tasks for easier debugging of crashes
This commit is contained in:
parent
4061c059ac
commit
ec7f982bdf
4 changed files with 91 additions and 78 deletions
|
@ -144,7 +144,11 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn listen_for_daemon_response(mut recv: DaemonResponseReceiver) {
|
fn listen_for_daemon_response(mut recv: DaemonResponseReceiver) {
|
||||||
let rt = tokio::runtime::Builder::new_current_thread().enable_time().build().expect("Failed to initialize tokio runtime");
|
let rt = tokio::runtime::Builder::new_current_thread()
|
||||||
|
.thread_name("listen-for-daemon-response")
|
||||||
|
.enable_all()
|
||||||
|
.build()
|
||||||
|
.expect("Failed to initialize tokio runtime");
|
||||||
rt.block_on(async {
|
rt.block_on(async {
|
||||||
if let Ok(Some(response)) = tokio::time::timeout(Duration::from_millis(100), recv.recv()).await {
|
if let Ok(Some(response)) = tokio::time::timeout(Duration::from_millis(100), recv.recv()).await {
|
||||||
println!("{}", response);
|
println!("{}", response);
|
||||||
|
|
|
@ -24,8 +24,14 @@ use yuck::config::script_var_definition::{ListenScriptVar, PollScriptVar, Script
|
||||||
/// the script var execution.
|
/// the script var execution.
|
||||||
pub fn init(evt_send: UnboundedSender<DaemonCommand>) -> ScriptVarHandlerHandle {
|
pub fn init(evt_send: UnboundedSender<DaemonCommand>) -> ScriptVarHandlerHandle {
|
||||||
let (msg_send, mut msg_recv) = tokio::sync::mpsc::unbounded_channel();
|
let (msg_send, mut msg_recv) = tokio::sync::mpsc::unbounded_channel();
|
||||||
let thread_handle = std::thread::spawn(move || {
|
let thread_handle = std::thread::Builder::new()
|
||||||
let rt = tokio::runtime::Runtime::new().expect("Failed to initialize tokio runtime for script var handlers");
|
.name("outer-script-var-handler".to_string())
|
||||||
|
.spawn(move || {
|
||||||
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
|
.enable_all()
|
||||||
|
.thread_name("script-var-handler")
|
||||||
|
.build()
|
||||||
|
.expect("Failed to initialize tokio runtime for script var handlers");
|
||||||
rt.block_on(async {
|
rt.block_on(async {
|
||||||
let _: Result<_> = try {
|
let _: Result<_> = try {
|
||||||
let mut handler = ScriptVarHandler {
|
let mut handler = ScriptVarHandler {
|
||||||
|
@ -49,7 +55,8 @@ pub fn init(evt_send: UnboundedSender<DaemonCommand>) -> ScriptVarHandlerHandle
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
});
|
})
|
||||||
|
.expect("Failed to start script-var-handler thread");
|
||||||
let handle = ScriptVarHandlerHandle { msg_send, thread_handle };
|
let handle = ScriptVarHandlerHandle { msg_send, thread_handle };
|
||||||
handle
|
handle
|
||||||
}
|
}
|
||||||
|
@ -279,15 +286,6 @@ impl ListenVarHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for ListenVarHandler {
|
|
||||||
fn drop(&mut self) {
|
|
||||||
let rt = tokio::runtime::Runtime::new().expect("Failed to initialize tokio runtime for script var handlers");
|
|
||||||
rt.block_on(async {
|
|
||||||
self.stop_all().await;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn terminate_handle(mut child: tokio::process::Child) {
|
async fn terminate_handle(mut child: tokio::process::Child) {
|
||||||
if let Some(id) = child.id() {
|
if let Some(id) = child.id() {
|
||||||
log::debug!("Killing process with id {}", id);
|
log::debug!("Killing process with id {}", id);
|
||||||
|
|
|
@ -116,8 +116,15 @@ pub fn initialize_server(paths: EwwPaths, action: Option<DaemonCommand>, should_
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_async_part(paths: EwwPaths, ui_send: UnboundedSender<app::DaemonCommand>) {
|
fn init_async_part(paths: EwwPaths, ui_send: UnboundedSender<app::DaemonCommand>) {
|
||||||
std::thread::spawn(move || {
|
std::thread::Builder::new()
|
||||||
let rt = tokio::runtime::Builder::new_multi_thread().enable_all().build().expect("Failed to initialize tokio runtime");
|
.name("outer-main-async-runtime".to_string())
|
||||||
|
.spawn(move || {
|
||||||
|
let rt = tokio::runtime::Builder::new_multi_thread()
|
||||||
|
.thread_name("main-async-runtime")
|
||||||
|
.enable_all()
|
||||||
|
.build()
|
||||||
|
.expect("Failed to initialize tokio runtime");
|
||||||
|
|
||||||
rt.block_on(async {
|
rt.block_on(async {
|
||||||
let filewatch_join_handle = {
|
let filewatch_join_handle = {
|
||||||
let ui_send = ui_send.clone();
|
let ui_send = ui_send.clone();
|
||||||
|
@ -147,7 +154,8 @@ fn init_async_part(paths: EwwPaths, ui_send: UnboundedSender<app::DaemonCommand>
|
||||||
log::error!("Eww exiting with error: {:?}", e);
|
log::error!("Eww exiting with error: {:?}", e);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
})
|
||||||
|
.expect("Failed to start outer-main-async-runtime thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Watch configuration files for changes, sending reload events to the eww app when the files change.
|
/// Watch configuration files for changes, sending reload events to the eww app when the files change.
|
||||||
|
|
|
@ -17,7 +17,9 @@ where
|
||||||
{
|
{
|
||||||
use wait_timeout::ChildExt;
|
use wait_timeout::ChildExt;
|
||||||
let cmd = replace_placeholders(cmd, args);
|
let cmd = replace_placeholders(cmd, args);
|
||||||
std::thread::spawn(move || {
|
std::thread::Builder::new()
|
||||||
|
.name("command-execution-thread".to_string())
|
||||||
|
.spawn(move || {
|
||||||
log::debug!("Running command from widget: {}", cmd);
|
log::debug!("Running command from widget: {}", cmd);
|
||||||
let child = Command::new("/bin/sh").arg("-c").arg(&cmd).spawn();
|
let child = Command::new("/bin/sh").arg("-c").arg(&cmd).spawn();
|
||||||
match child {
|
match child {
|
||||||
|
@ -33,7 +35,8 @@ where
|
||||||
},
|
},
|
||||||
Err(err) => log::error!("Failed to launch child process: {}", err),
|
Err(err) => log::error!("Failed to launch child process: {}", err),
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
.expect("Failed to start command-execution-thread");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn replace_placeholders<T>(cmd: &str, args: &[T]) -> String
|
fn replace_placeholders<T>(cmd: &str, args: &[T]) -> String
|
||||||
|
|
Loading…
Add table
Reference in a new issue