inconsistent file descriptor blocking state when running in asyncio vs uvloop
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- python
- Domain
- operating-systems
Research direction
Start by running the supplied asyncio versus uvloop reproduction and inspect the uvloop entry points for loop.add_reader() and loop.add_writer(). Compare their file-descriptor handling with the standard asyncio selector loop; done means registering stdin, stdout, and stderr preserves their blocking state under uvloop.
Written by the indexing model from the issue text.
Description
When running under uvloop, registering stdin, stdout, or stderr with loop.add_reader() / loop.add_writer() implicitly changes their blocking mode from blocking to non-blocking. This behaviour does not occur under the standard asyncio selector event loop.
This is causing some issues when running with rich/promptkit in fast-agent
Under the following test code
import anyio
import sys
import os
import asyncio
async def main():
loop = asyncio.get_running_loop()
print(f"Using event loop: {type(loop)}")
stdin = sys.stdin.fileno()
stdout = sys.stdout.fileno()
stderr = sys.stderr.fileno()
print(f"initial:\tstdin fd: {stdin}, stdout fd: {stdout}, stderr fd: {stderr}")
print(f"blocking:\tstdin fd: {os.get_blocking(stdin)}, stdout fd: {os.get_blocking(stdout)}, stderr fd: {os.get_blocking(stderr)}")
loop.add_writer(stdin, lambda: None)
loop.add_writer(stdout, lambda: None)
loop.add_writer(stderr, lambda: None)
print(f"writer: \tstdin fd: {stdin}, stdout fd: {stdout}, stderr fd: {stderr}")
print(f"blocking:\tstdin fd: {os.get_blocking(stdin)}, stdout fd: {os.get_blocking(stdout)}, stderr fd: {os.get_blocking(stderr)}")
loop.add_reader(stdin, lambda: None)
loop.add_reader(stdout, lambda: None)
loop.add_reader(stderr, lambda: None)
print(f"reader: \tstdin fd: {stdin}, stdout fd: {stdout}, stderr fd: {stderr}")
print(f"blocking:\tstdin fd: {os.get_blocking(stdin)}, stdout fd: {os.get_blocking(stdout)}, stderr fd: {os.get_blocking(stderr)}")
anyio.run(main, backend="asyncio", backend_options={"use_uvloop": False})
print("-" * 40)
anyio.run(main, backend="asyncio", backend_options={"use_uvloop": True})
I see the following output, where the blocking status of the stdio file descriptors are changed from blocking to non blocking when running under uvloop but not asyncio.
Using event loop: <class 'asyncio.unix_events._UnixSelectorEventLoop'>
initial: stdin fd: 0, stdout fd: 1, stderr fd: 2
blocking: stdin fd: True, stdout fd: True, stderr fd: True
writer: stdin fd: 0, stdout fd: 1, stderr fd: 2
blocking: stdin fd: True, stdout fd: True, stderr fd: True
reader: stdin fd: 0, stdout fd: 1, stderr fd: 2
blocking: stdin fd: True, stdout fd: True, stderr fd: True
----------------------------------------
Using event loop: <class 'uvloop.Loop'>
initial: stdin fd: 0, stdout fd: 1, stderr fd: 2
blocking: stdin fd: True, stdout fd: True, stderr fd: True
writer: stdin fd: 0, stdout fd: 1, stderr fd: 2
blocking: stdin fd: False, stdout fd: False, stderr fd: False
reader: stdin fd: 0, stdout fd: 1, stderr fd: 2
blocking: stdin fd: False, stdout fd: False, stderr fd: False
- Dominant language
- Cython
- Stars
- 11.9k
- Forks
- 615
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MagicStack/uvloop
-
License not clear Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MagicStack/uvloop#759 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MagicStack/uvloop#741 · 2 reactions ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
MagicStack/uvloop#702 · 8 comments · 9 reactions ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
MagicStack/uvloop#766 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 52/100
MagicStack/uvloop#765 ·
All issues in MagicStack/uvloop
Similar issues
-
next-devel: s390x build fails — chccwdev/vmur/zkey missing from initramfs after s390utils 2.44 split Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
coreos/fedora-coreos-tracker#2228 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
pop-os/plymouth-theme#43 ·
-
[addtool] DeepZero Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
gwen001/offsectools_www#2055 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
libsdl-org/SDL#16372 ·