-
Notifications
You must be signed in to change notification settings - Fork 204
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
Make downloads asyncronous #42
Comments
Hello, The dependencies download is asynchronous. The code is located at: rust-bert/src/common/resources.rs Line 182 in 60bffe6
I believe the problem is that I declared a #[tokio::main] which would not allow you to do so in your main application.
I am pushing some changes to make the overall function synchronous and use a local runtime instead. As I do not have code available to reproduce the issue, could you please check-out the branch |
Sorry for not mentioning, basically the reproduction is: use rust_bert::pipelines::sentiment::SentimentModel;
#[tokio::main]
async fn main() {
let model = SentimentModel::new(Default::default()).unwrap();
// or
let model = tokio::task::block_in_place(|| SentimentModel::new(Default::default())).unwrap();
// or the following which you cannot do due to rust complaining about sending Rc between threads
let model = tokio::task::spawn_blocking(|| SentimentModel::new(Default::default()).unwrap())
.await.unwrap();
} It should produce the |
Hello, The library is by design currently synchronous, because the download part of it is a minimal feature. #[tokio::main]
async fn main() {
task::spawn_blocking(move || { let model = SentimentModel::new(Default::default()).unwrap(); });
} |
I failed to integrate this library into my application which natively uses
async/await
andtokio
.I simply cannot create a model, because I get
every time I try to create
SentimentModel::new()
.I may be a newbie in tokio, so I tried
But this didn't solve the problem.
Also doing this:
also doesn't work because
Rust
complaints about sending some internalstd::rc::Rc
between threads. Even wrapping it all withArc<Mutex<SentimentModel>>
doesn't help.I am simply perplexed and don't know how to use this crate inside of
async fn
s...The text was updated successfully, but these errors were encountered: