Skip to content

Why is calling sync from a running loop a bad idea? #1570

You must be logged in to vote

Unfortunately, the event loop in asyncio is non-reentrant. That means, you cannot say "hey loop, run this" from within the loop. The only way to do that is await, but you can't do that in a non-async function. So you must do one or the other: use sync(), or await on async methods.

sync() works by using a dedicated IO thread, since we can wait on thread signaling primitives live event in a normal function. If you are running your whole application as async, you don't need another thread.

Replies: 2 comments 4 replies

You must be logged in to vote
2 replies
@martindurant

@freddyaboulton

Answer selected by freddyaboulton

You must be logged in to vote
2 replies
@martindurant

@MarcSkovMadsen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants