Content-Length: 351531 | pFad | http://github.com/postgresml/postgresml/pull/1386/files

59 Added once_cell crate to make RUNTIME lazy by SilasMarvin · Pull Request #1386 · postgresml/postgresml · GitHub
Skip to content

Added once_cell crate to make RUNTIME lazy #1386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pgml-sdks/pgml/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pgml-sdks/pgml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ colored = "2"
ctrlc = "3"
inquire = "0.6"
parking_lot = "0.12.1"
once_cell = "1.19.0"

[features]
default = []
Expand Down
24 changes: 8 additions & 16 deletions pgml-sdks/pgml/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//!
//! With this SDK, you can seamlessly manage various database tables related to documents, text chunks, text splitters, LLM (Language Model) models, and embeddings. By leveraging the SDK's capabilities, you can efficiently index LLM embeddings using PgVector for fast and accurate queries.

use once_cell::sync::Lazy;
use parking_lot::RwLock;
use sqlx::{postgres::PgPoolOptions, PgPool};
use std::collections::HashMap;
Expand Down Expand Up @@ -123,24 +124,15 @@ fn internal_init_logger(level: Option<String>, format: Option<String>) -> anyhow

// Normally the global async runtime is handled by tokio but because we are a library being called
// by javascript and other langauges, we occasionally need to handle it ourselves
#[allow(dead_code)]
static mut RUNTIME: Option<Runtime> = None;
static RUNTIME: Lazy<Runtime> = Lazy::new(|| {
Builder::new_multi_thread()
.enable_all()
.build()
.expect("Error creating tokio runtime")
});

#[allow(dead_code)]
fn get_or_set_runtime<'a>() -> &'a Runtime {
unsafe {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, makes sense. This is totally not thread safe!

if let Some(r) = &RUNTIME {
r
} else {
// Need to use multi thread for JavaScript
let runtime = Builder::new_multi_thread()
.enable_all()
.build()
.expect("Error creating tokio runtime");
RUNTIME = Some(runtime);
get_or_set_runtime()
}
}
&RUNTIME
}

#[cfg(feature = "python")]
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/postgresml/postgresml/pull/1386/files

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy