Skip to content
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

Asyncio's loop.create_unix_server makes blocking calls #129807

Closed
cbornet opened this issue Feb 7, 2025 · 6 comments
Closed

Asyncio's loop.create_unix_server makes blocking calls #129807

cbornet opened this issue Feb 7, 2025 · 6 comments
Labels
stdlib Python modules in the Lib dir topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@cbornet
Copy link

cbornet commented Feb 7, 2025

Bug report

Bug description:

It seems create_unix_server makes some calls to blocking functions.

async def create_unix_server(

In particular:

CPython versions tested on:

3.11

Operating systems tested on:

No response

@cbornet cbornet added the type-bug An unexpected behavior, bug, or error label Feb 7, 2025
@github-project-automation github-project-automation bot moved this to Todo in asyncio Feb 7, 2025
@picnixz picnixz added the stdlib Python modules in the Lib dir label Feb 7, 2025
@ZeroIntensity
Copy link
Member

cc @graingert

@gvanrossum
Copy link
Member

The calls you mention are not worth making asynchronous -- we'd just be making a simple thing complicated for no reason.

  • Modern filesystems use caching and filesystem operations are effectively synchronous. People have looked into making async versions of filesystem operations and IIRC the conclusion was that it wasn't worth the complexity -- no actual parallelism was gained.

  • It's the same for bind() -- it does no actual I/O, it just copies some bytes from user space to kernel space.

@gvanrossum gvanrossum closed this as not planned Won't fix, can't repro, duplicate, stale Feb 8, 2025
@github-project-automation github-project-automation bot moved this from Todo to Done in asyncio Feb 8, 2025
@cbornet
Copy link
Author

cbornet commented Feb 10, 2025

Thanks for the quick feedback.
Wouldn't delegating these operations to a thread allow to release the GIL and to not block the rest of the loop ? I think that's what other event loop systems such as Node.js do, even for simple syscalls such as stat.
As for the bind, the trio issue says that "it has to do filesystem traversal", doesn't it count as a blocking op ?

In general, it would be nice to have guidelines in the asyncio docs as to which framework functions are considered blocking and which are not.

@gvanrossum
Copy link
Member

I don’t understand if you’re arguing from a conceptual purity concern, or if this has caused you problems in an actual project?

@cbornet
Copy link
Author

cbornet commented Feb 10, 2025

It's more conceptual and looking for best practices, that make the system the most stable and performant.
Also, I wrote a tool lib to detect blocking calls called blockbuster (it's how I saw these os calls in asyncio) and would be interested in knowing which functions should trigger it. But that's probably something to discuss elsewhere.

@gvanrossum
Copy link
Member

Okay, thanks. Then I will keep this closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-asyncio type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

4 participants