-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
calling futures::executor::block_on in block_in_place may hang #2603
Comments
Use |
@Darksonn thank you for pointing me to that alternative, I hadn't considered it. But is it not a potential bug that the task budget keeps counting within |
I feel like there is room for improvement here. There are a lot of blocking options... |
Calling |
Generally, the answer is to not use Besides that, you only really need to pick between |
Re: @That3Percent Unless you are doing something complicated, you shouldn't be using anything but Tokio's Tokio's The The global knowledge thing you talk about is indicative of either not using Unfortunately there are no ways to lint or otherwise detect missing |
If the code in question is deeper in the call stack, what should I do? Calling I've got a small crate inside a larger application, and that larger application is using actix-web (and hence tokio) to serve web and GraphQL content. This smaller crate is thoroughly synchronous. It is one of several similar crates, so changing everything to asynchronous is a big change. This small crate is calling a library function that returns a I'm sure this is a stupid question, and I apologize for that. I've spent several hours reading documentation and trying everything I could think of, short of hand-rolling my own executor. Should I give up and change the entire application to be asynchronous everywhere so I can call this one function? Thanks for tokio by the way, the docs are well written and the API is rather extensive. |
@nlfiedler You should make use of the fact that calling I recommend using our Note that if your synchronous code does anything else blocking such as using std IO types, then you must use |
Thank you for the explanation, that confirms what I was afraid of. This application started two years ago, long before async/await was stabilized. The async aspects of the application consist of the |
You could consider using |
Yes, I saw that, and it is helpful for a situation other than mine. I need to realize the results of the Anyway, I've derailed this issue long enough. Thanks for your help. |
You can use |
Yep, tried that -- you get "runtime inside a runtime" error. |
Try again w/ the latest release? #2711 might have fixed it. |
…or::block_on` Because `futures::executor::block_on` sometimes did deadlocks and it's another async executor, so it's not recommended to mix multiple executors at the same time. tokio-rs/tokio#2603 (comment)
Version
0.2.21
Platform
Linux
Description
I'm basically having the problem in this issue #2376, which is to use
block_on
within a tokio task, and sometimes it hangs. This comment #2376 (comment) says usingspawn_blocking
fixes it. I figuredblock_in_place
should also work, but it didn't. A guess for why is that when usingblock_in_place
the thread local variable for the task budget continues to decrease, when it should stop counting. Possibly as was done for LocalSet.The text was updated successfully, but these errors were encountered: