Skip to content

Commit 762dabb

Browse files
authored
Handle requests in a separate thread (#78)
1 parent e72d65a commit 762dabb

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

crates/pet/src/jsonrpc.rs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,38 +82,41 @@ impl RefreshResult {
8282
pub fn handle_refresh(context: Arc<Context>, id: u32, params: Value) {
8383
match serde_json::from_value::<RequestOptions>(params.clone()) {
8484
Ok(request_options) => {
85-
let mut cfg = context.configuration.write().unwrap();
86-
cfg.search_paths = request_options.search_paths;
87-
cfg.conda_executable = request_options.conda_executable;
88-
drop(cfg);
89-
let config = context.configuration.read().unwrap().clone();
90-
for locator in context.locators.iter() {
91-
locator.configure(&config);
92-
}
93-
let summary = find_and_report_envs(
94-
context.reporter.as_ref(),
95-
config,
96-
&context.locators,
97-
context.conda_locator.clone(),
98-
);
99-
let summary = summary.lock().unwrap();
100-
for locator in summary.find_locators_times.iter() {
101-
info!("Locator {} took {:?}", locator.0, locator.1);
102-
}
103-
info!(
104-
"Environments found using locators in {:?}",
105-
summary.find_locators_time
106-
);
107-
info!("Environments in PATH found in {:?}", summary.find_path_time);
108-
info!(
109-
"Environments in global virtual env paths found in {:?}",
110-
summary.find_global_virtual_envs_time
111-
);
112-
info!(
113-
"Environments in custom search paths found in {:?}",
114-
summary.find_search_paths_time
115-
);
116-
send_reply(id, Some(RefreshResult::new(summary.time)));
85+
// Start in a new thread, we can have multiple requests.
86+
thread::spawn(move || {
87+
let mut cfg = context.configuration.write().unwrap();
88+
cfg.search_paths = request_options.search_paths;
89+
cfg.conda_executable = request_options.conda_executable;
90+
drop(cfg);
91+
let config = context.configuration.read().unwrap().clone();
92+
for locator in context.locators.iter() {
93+
locator.configure(&config);
94+
}
95+
let summary = find_and_report_envs(
96+
context.reporter.as_ref(),
97+
config,
98+
&context.locators,
99+
context.conda_locator.clone(),
100+
);
101+
let summary = summary.lock().unwrap();
102+
for locator in summary.find_locators_times.iter() {
103+
info!("Locator {} took {:?}", locator.0, locator.1);
104+
}
105+
info!(
106+
"Environments found using locators in {:?}",
107+
summary.find_locators_time
108+
);
109+
info!("Environments in PATH found in {:?}", summary.find_path_time);
110+
info!(
111+
"Environments in global virtual env paths found in {:?}",
112+
summary.find_global_virtual_envs_time
113+
);
114+
info!(
115+
"Environments in custom search paths found in {:?}",
116+
summary.find_search_paths_time
117+
);
118+
send_reply(id, Some(RefreshResult::new(summary.time)));
119+
});
117120
}
118121
Err(e) => {
119122
send_reply(id, None::<u128>);

0 commit comments

Comments
 (0)