Python os.closerange() Method
Example
Close all file descriptors with os.closerange():
# import os Library
import os
# define file paths to be opened
path1 = "file1.txt"
path2 = "file2.txt"
path3 = "file3.txt"
# open files and get the file descriptor
fd1 = os.open(path1,
os.O_RDWR | os.O_CREAT)
fd2 = os.open(path2, os.O_RDWR | os.O_CREAT)
fd3 = os.open(path3, os.O_RDWR | os.O_CREAT)
# here, do something
with the files
# close all file descriptors with os.closerange()
fd_low = min(fd1, fd2, fd3)
fd_high = max(fd1, fd2, fd3)
os.closerange(fd_low, fd_high + 1)
Definition and Usage
The os.closerange()
method closes all file descriptors
from fd_low (inclusive) to fd_high (exclusive). Any error occurred while closing any of the file descriptor is ignored.
Syntax
os.closerange(fd_low, fd_high)
Parameter Values
Parameter | Description |
---|---|
fd_low | Required. The lowest file descriptor to be closed |
fd_high | Required. The highest file descriptor to be closed |
Technical Details
Return Value: | None |
---|---|
Python Version: | 2.6 |