Saturday, September 6, 2025
HomeLanguagesPython | os.get_blocking() method

Python | os.get_blocking() method

OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.

os.get_blocking() method in Python is used to get the blocking mode information of the specified file descriptor.

This method returns True if the os.O_NONBLOCK flag is unset which means that the specified file descriptor is in blocking mode and False if the os.O_NONBLOCK flag is set which means that the specified file descriptor is in non-blocking mode.

A file descriptor in blocking mode means that I/O system calls like read, write, or connect can be blocked by the system.
For example: If we call read system call on stdin then our program will get blocked (the kernel will put the process into the sleeping state) until data to be read is actually available on stdin.

Note: os.get_blocking() method is available on Unix platforms only.

Syntax: os.get_blocking(fd)

Parameter:
fd: A file descriptor whose blocking mode information is required.

Return Type: This method returns a Boolean value of class ‘bool’. True denotes that the file descriptor is in blocking mode while False denotes that the file descriptor is in non-blocking mode.

Code: Use of os.get_blocking() method to get the blocking mode of a file descriptor




# Python program to explain os.get_blocking() method 
    
# importing os module 
import os
  
# File path 
path = "/home / ihritik / Documents / file.txt"
  
  
# Open the file and get
# the file descriptor associated
# with it using os.open() method
fd = os.open(path, os.O_RDWR)
  
  
# Get the blocking mode
# of the file descriptor
# using os.get_blocking() method
mode = os.get_blocking(fd)
  
if mode == True:
    print("File descriptor is in blocking mode")
else :
    print("File descriptor is in Non-blocking mode")
  
  
# Close the file descriptor
os.close(fd)


Output:

File descriptor is in blocking mode
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32270 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11869 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS