Python Glossary Русский

Python 3.5+osfunction

os.get_blocking

os — descriptor mode

Check whether a descriptor is in blocking I/O mode. On Windows since Python 3.12, and for pipes only.

Syntax

os.get_blocking(...)

A non-blocking descriptor raises BlockingIOError instead of waiting when no data is available. asyncio and selectors work this way: they switch sockets and pipes to non-blocking mode. On Windows, since 3.12, only pipes are supported.

Examples

import os
r, w = os.pipe()
print(os.get_blocking(r))   # → только Unix: True — новый канал открыт в блокирующем режиме
os.set_blocking(r, False)   # → только Unix: переводим тот же дескриптор в неблокирующий режим
print(os.get_blocking(r))   # → только Unix: False — get_blocking видит изменение флага O_NONBLOCK
print(os.get_blocking(9999))   # → только Unix: OSError (EBADF, Bad file descriptor) — такого дескриптора нет

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy