Skip to content

Commit

Permalink
[fix/issue1] improved solution: create runtime in callback
Browse files Browse the repository at this point in the history
  • Loading branch information
toschoo committed Jan 31, 2024
1 parent 75d7397 commit a5097a9
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
10 changes: 0 additions & 10 deletions crates/edgen_rt_llama_cpp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use tokio::sync::mpsc::{unbounded_channel, UnboundedSender};
use tokio::task::JoinHandle;
use tokio::time::{interval, MissedTickBehavior};
use tokio::{select, spawn};
use tokio::runtime::{Handle, Runtime};
use tracing::{error, info};

use edgen_core::llm::{
Expand Down Expand Up @@ -123,15 +122,6 @@ impl LLMEndpoint for LlamaCppEndpoint {
impl Default for LlamaCppEndpoint {
fn default() -> Self {
let models: Arc<DashMap<String, UnloadingModel>> = Default::default();

let (handle, _rt) = match Handle::try_current() {
Ok(h) => (h, None),
Err(_) => {
let rt = Runtime::new().unwrap();
(rt.handle().clone(), Some(rt))
},
};
let _guard = handle.enter();
let models_clone = models.clone();
let cleanup_thread = spawn(async move {
let mut interval = interval(cleanup_interval());
Expand Down
2 changes: 2 additions & 0 deletions crates/edgen_server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ async fn run_server(args: &cli::Serve) -> bool {
let flag_clone = reset_flag.clone();

let _callback_handle = SETTINGS.read().await.add_change_callback(move || {
let rt = tokio::runtime::Runtime::new().unwrap();
let _guard = rt.enter();
flag_clone.store(true, Ordering::SeqCst);
reset_channels.clear();
block_on(crate::llm::reset_environment());
Expand Down

0 comments on commit a5097a9

Please sign in to comment.