python / python/cpython

Failure during the print of select.select output with unblocking sys.stdin

Open
#126,468 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules topic-socket type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:

This code terminates with error messages after several loop iterations:

import sys
import os
import select

os.set_blocking(sys.stdin.fileno(), False)

while True:
    print('>')
    ready = select.select([sys.stdin, ], [], [], 0.0)[0]
    print(f'< ready={ready}')
$ python3.11 stdin-nonblocking-bug-report.py
<... skip many iterations ...>
< ready=[]
>
< ready=[]
>
< ready=[]
Traceback (most recent call last):
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
Exception ignored in sys.unraisablehook: <built-in function unraisablehook>

$ echo $?
120

The failure occurs in print(f'< ready={ready}').

Python-3.11
FreeBSD 14.1

CPython versions tested on:

3.11

Operating systems tested on:

Other

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided reproducer that sets sys.stdin nonblocking and repeatedly calls select.select before printing. Reproduce the failure on Python 3.11 with FreeBSD 14.1, then trace the stdout print and shutdown path to identify the cause. Done means the loop no longer produces the reported unraisable I/O error under the stated conditions.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.