Python Glossary Русский

Python 3.3+Linuxosfunction

os.posix_fadvise

os — kernel hints

Advise the kernel about the expected file access pattern. Availability: Linux.

Syntax

os.posix_fadvise(...)

It is only advice: the kernel may ignore it, and it never affects correctness. POSIX_FADV_SEQUENTIAL speeds up reading large files front to back, and POSIX_FADV_DONTNEED keeps a file you will not need again from crowding the page cache. A length of 0 means "to the end of the file".

Examples

import os
with open('report.csv', 'w') as f:
    f.write('a,b\n1,2\n')   # файл для примера — в текущем каталоге
fd = os.open('report.csv', os.O_RDONLY)   # → ? только Unix: небольшой номер дескриптора, например 3
os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_SEQUENTIAL)   # → ? только Unix: подсказка «читать будем подряд»; length=0 означает «до конца файла»
os.posix_fadvise(fd, 0, 65536, os.POSIX_FADV_WILLNEED)   # → ? только Unix: ядро заранее подтянет первые 64 КБ файла в кеш
os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_DONTNEED)   # → ? только Unix: после однопроходного чтения просим освободить кеш под этот файл
os.posix_fadvise(fd, 0, 0, 999)   # → ? только Unix: OSError [Errno 22] Invalid argument — 999 не является кодом совета

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy