Closed trivialfis closed 4 weeks ago
What happens here is that calling .sync()
always assumes the function returns an awaitable, which is obviously not the case if the function is synchronous as in the original post. However, the docstring doesn't really define whether this is intentional or not, but the sync
function which is called internally clarifies that func
must be a coroutine. With that said, it seems to me that this is indeed intentional, everything that is called with sync()
should return an awaitable, all existing tests assume that too. I'll not claim I know the reasoning behind that decision, but I suspect it is indeed intentional because without this it leaves the door open for users to write blocking code that may never allow the event loop to continue progressing and thus block the application indefinitely.
I think it's probably important to determine whether your function can be made asynchronous, and if not let us know the constraints here. Maybe Distributed maintainers who are more familiar with the internals would also have further comments on the sync()
design and constraints, or suggestions how to move forward.
@pentschev Thank you for the explanation and the references, that makes sense.
I think it's probably important to determine whether your function can be made asynchronous
We have been doing that. I was trying to simplify the code in XGBoost, and the async seems difficult to handle when we also need to handle synchronous code.
It's fine if this is intended behavior. I will close this issue now.
Describe the issue:
Two unexpected errors when calling
get_client
inside a function called byclient.sync
:We use the
client.sync
method to handle asynchronous and synchronous environments uniformly in XGBoost. I'm not sure if this is the best way to write libraries, please share if there's a better approach.Error message:
Minimal Complete Verifiable Example:
Environment: