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.closerange() method in Python is used to close all file descriptors in the range fd_low (inclusive) to fd_high (exclusive). Any error occurred while closing any of the file descriptor in the given range is ignored.
A file descriptor is small integer value that corresponds to a file or other input/output resource, such as a pipe or network socket. A File descriptor is an abstract indicator of a resource and act as handle to perform various lower level I/O operations like read, write, send etc.
For Example: Standard input is usually file descriptor with value 0, standard output is usually file descriptor with value 1 and standard error is usually file descriptor with value 2.
Further files opened by the current process will get the value 3, 4, 5 an so on.
Syntax: os.closerange(fd_low, fd_high)
fd_low: The Lowest file descriptor to be closed.
fd_high: The highest file descriptor to be closed.
Return Type: This method does not return any value
Code: Use of
os.closerange() method to close file descriptors in the given range
All file descriptor closed successfully
os.closerange() method is equivalent to following python code:
os.closerange() method works faster than above code.
- class method vs static method in Python
- Python | os.dup() method
- Python | set() method
- Python | next() method
- Python | os.sysconf() method
- Python | os.wait() method
- Python | os.sched_get_priority_min() method
- Python | os.sched_get_priority_max() method
- Python | os.sched_rr_get_interval() method
- Python | os.fchmod() method
- Python | os.WIFCONTINUED() method
- Python | os.sched_getaffinity() method
- Python | os.sched_setaffinity() method
- Python | os.WIFSIGNALED() method
- Python | os.WSTOPSIG() method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.