Generic Operating System Services¶
The modules described in this chapter provide interfaces to operating system features that are available on (almost) all operating systems, such as files and a clock. The interfaces are generally modeled after the Unix or C interfaces, but they are available on most other systems as well. Here’s an overview:
os
— Miscellaneous operating system interfaceserror
name
- File Names, Command Line Arguments, and Environment Variables
- Python UTF-8 Mode
- Process Parameters
ctermid()
environ
environb
fsencode()
fsdecode()
fspath()
PathLike
getenv()
getenvb()
get_exec_path()
getegid()
geteuid()
getgid()
getgrouplist()
getgroups()
getlogin()
getpgid()
getpgrp()
getpid()
getppid()
getpriority()
PRIO_PROCESS
PRIO_PGRP
PRIO_USER
getresuid()
getresgid()
getuid()
initgroups()
putenv()
setegid()
seteuid()
setgid()
setgroups()
setpgrp()
setpgid()
setpriority()
setregid()
setresgid()
setresuid()
setreuid()
getsid()
setsid()
setuid()
strerror()
supports_bytes_environ
umask()
uname()
unsetenv()
- File Object Creation
- File Descriptor Operations
close()
closerange()
copy_file_range()
device_encoding()
dup()
dup2()
fchmod()
fchown()
fdatasync()
fpathconf()
fstat()
fstatvfs()
fsync()
ftruncate()
get_blocking()
isatty()
lockf()
F_LOCK
F_TLOCK
F_ULOCK
F_TEST
login_tty()
lseek()
SEEK_SET
SEEK_CUR
SEEK_END
open()
O_RDONLY
O_WRONLY
O_RDWR
O_APPEND
O_CREAT
O_EXCL
O_TRUNC
O_DSYNC
O_RSYNC
O_SYNC
O_NDELAY
O_NONBLOCK
O_NOCTTY
O_CLOEXEC
O_BINARY
O_NOINHERIT
O_SHORT_LIVED
O_TEMPORARY
O_RANDOM
O_SEQUENTIAL
O_TEXT
O_EVTONLY
O_FSYNC
O_SYMLINK
O_NOFOLLOW_ANY
O_ASYNC
O_DIRECT
O_DIRECTORY
O_NOFOLLOW
O_NOATIME
O_PATH
O_TMPFILE
O_SHLOCK
O_EXLOCK
openpty()
pipe()
pipe2()
posix_fallocate()
posix_fadvise()
POSIX_FADV_NORMAL
POSIX_FADV_SEQUENTIAL
POSIX_FADV_RANDOM
POSIX_FADV_NOREUSE
POSIX_FADV_WILLNEED
POSIX_FADV_DONTNEED
pread()
preadv()
RWF_NOWAIT
RWF_HIPRI
pwrite()
pwritev()
RWF_DSYNC
RWF_SYNC
RWF_APPEND
read()
sendfile()
set_blocking()
SF_NODISKIO
SF_MNOWAIT
SF_SYNC
SF_NOCACHE
splice()
SPLICE_F_MOVE
SPLICE_F_NONBLOCK
SPLICE_F_MORE
readv()
tcgetpgrp()
tcsetpgrp()
ttyname()
write()
writev()
- Querying the size of a terminal
- Inheritance of File Descriptors
- Files and Directories
access()
F_OK
R_OK
W_OK
X_OK
chdir()
chflags()
chmod()
chown()
chroot()
fchdir()
getcwd()
getcwdb()
lchflags()
lchmod()
lchown()
link()
listdir()
lstat()
mkdir()
makedirs()
mkfifo()
mknod()
major()
minor()
makedev()
pathconf()
pathconf_names
readlink()
remove()
removedirs()
rename()
renames()
replace()
rmdir()
scandir()
DirEntry
stat()
stat_result
stat_result.st_mode
stat_result.st_ino
stat_result.st_dev
stat_result.st_nlink
stat_result.st_uid
stat_result.st_gid
stat_result.st_size
stat_result.st_atime
stat_result.st_mtime
stat_result.st_ctime
stat_result.st_atime_ns
stat_result.st_mtime_ns
stat_result.st_ctime_ns
stat_result.st_blocks
stat_result.st_blksize
stat_result.st_rdev
stat_result.st_flags
stat_result.st_gen
stat_result.st_birthtime
stat_result.st_fstype
stat_result.st_rsize
stat_result.st_creator
stat_result.st_type
stat_result.st_file_attributes
stat_result.st_reparse_tag
statvfs()
supports_dir_fd
supports_effective_ids
supports_fd
supports_follow_symlinks
symlink()
sync()
truncate()
unlink()
utime()
walk()
fwalk()
memfd_create()
MFD_CLOEXEC
MFD_ALLOW_SEALING
MFD_HUGETLB
MFD_HUGE_SHIFT
MFD_HUGE_MASK
MFD_HUGE_64KB
MFD_HUGE_512KB
MFD_HUGE_1MB
MFD_HUGE_2MB
MFD_HUGE_8MB
MFD_HUGE_16MB
MFD_HUGE_32MB
MFD_HUGE_256MB
MFD_HUGE_512MB
MFD_HUGE_1GB
MFD_HUGE_2GB
MFD_HUGE_16GB
eventfd()
eventfd_read()
eventfd_write()
EFD_CLOEXEC
EFD_NONBLOCK
EFD_SEMAPHORE
- Linux extended attributes
- Process Management
abort()
add_dll_directory()
execl()
execle()
execlp()
execlpe()
execv()
execve()
execvp()
execvpe()
_exit()
EX_OK
EX_USAGE
EX_DATAERR
EX_NOINPUT
EX_NOUSER
EX_NOHOST
EX_UNAVAILABLE
EX_SOFTWARE
EX_OSERR
EX_OSFILE
EX_CANTCREAT
EX_IOERR
EX_TEMPFAIL
EX_PROTOCOL
EX_NOPERM
EX_CONFIG
EX_NOTFOUND
fork()
forkpty()
kill()
killpg()
nice()
pidfd_open()
plock()
popen()
posix_spawn()
POSIX_SPAWN_OPEN
POSIX_SPAWN_CLOSE
POSIX_SPAWN_DUP2
posix_spawnp()
register_at_fork()
spawnl()
spawnle()
spawnlp()
spawnlpe()
spawnv()
spawnve()
spawnvp()
spawnvpe()
P_NOWAIT
P_NOWAITO
P_WAIT
P_DETACH
P_OVERLAY
startfile()
system()
times()
wait()
waitid()
waitpid()
wait3()
wait4()
P_PID
P_PGID
P_ALL
P_PIDFD
WCONTINUED
WEXITED
WSTOPPED
WUNTRACED
WNOHANG
WNOWAIT
CLD_EXITED
CLD_KILLED
CLD_DUMPED
CLD_TRAPPED
CLD_STOPPED
CLD_CONTINUED
waitstatus_to_exitcode()
WCOREDUMP()
WIFCONTINUED()
WIFSTOPPED()
WIFSIGNALED()
WIFEXITED()
WEXITSTATUS()
WSTOPSIG()
WTERMSIG()
- Interface to the scheduler
SCHED_OTHER
SCHED_BATCH
SCHED_IDLE
SCHED_SPORADIC
SCHED_FIFO
SCHED_RR
SCHED_RESET_ON_FORK
sched_param
sched_get_priority_min()
sched_get_priority_max()
sched_setscheduler()
sched_getscheduler()
sched_setparam()
sched_getparam()
sched_rr_get_interval()
sched_yield()
sched_setaffinity()
sched_getaffinity()
- Miscellaneous System Information
- Random numbers
io
— Core tools for working with streamstime
— Time access and conversions- Functions
asctime()
pthread_getcpuclockid()
clock_getres()
clock_gettime()
clock_gettime_ns()
clock_settime()
clock_settime_ns()
ctime()
get_clock_info()
gmtime()
localtime()
mktime()
monotonic()
monotonic_ns()
perf_counter()
perf_counter_ns()
process_time()
process_time_ns()
sleep()
strftime()
strptime()
struct_time
time()
time_ns()
thread_time()
thread_time_ns()
tzset()
- Clock ID Constants
- Timezone Constants
- Functions
argparse
— Parser for command-line options, arguments and sub-commands- Core Functionality
- Quick Links for add_argument()
- Example
- ArgumentParser objects
- The add_argument() method
- The parse_args() method
- Other utilities
- Upgrading optparse code
getopt
— C-style parser for command line optionslogging
— Logging facility for Python- Logger Objects
Logger
Logger.propagate
Logger.setLevel()
Logger.isEnabledFor()
Logger.getEffectiveLevel()
Logger.getChild()
Logger.debug()
Logger.info()
Logger.warning()
Logger.error()
Logger.critical()
Logger.log()
Logger.exception()
Logger.addFilter()
Logger.removeFilter()
Logger.filter()
Logger.addHandler()
Logger.removeHandler()
Logger.findCaller()
Logger.handle()
Logger.makeRecord()
Logger.hasHandlers()
- Logging Levels
- Handler Objects
- Formatter Objects
- Filter Objects
- LogRecord Objects
- LogRecord attributes
- LoggerAdapter Objects
- Thread Safety
- Module-Level Functions
- Module-Level Attributes
- Integration with the warnings module
- Logger Objects
logging.config
— Logging configurationlogging.handlers
— Logging handlersgetpass
— Portable password inputcurses
— Terminal handling for character-cell displays- Functions
error
baudrate()
beep()
can_change_color()
cbreak()
color_content()
color_pair()
curs_set()
def_prog_mode()
def_shell_mode()
delay_output()
doupdate()
echo()
endwin()
erasechar()
filter()
flash()
flushinp()
getmouse()
getsyx()
getwin()
has_colors()
has_extended_color_support()
has_ic()
has_il()
has_key()
halfdelay()
init_color()
init_pair()
initscr()
is_term_resized()
isendwin()
keyname()
killchar()
longname()
meta()
mouseinterval()
mousemask()
napms()
newpad()
newwin()
nl()
nocbreak()
noecho()
nonl()
noqiflush()
noraw()
pair_content()
pair_number()
putp()
qiflush()
raw()
reset_prog_mode()
reset_shell_mode()
resetty()
resize_term()
resizeterm()
savetty()
get_escdelay()
set_escdelay()
get_tabsize()
set_tabsize()
setsyx()
setupterm()
start_color()
termattrs()
termname()
tigetflag()
tigetnum()
tigetstr()
tparm()
typeahead()
unctrl()
ungetch()
update_lines_cols()
unget_wch()
ungetmouse()
use_env()
use_default_colors()
wrapper()
- Window Objects
window.addch()
window.addnstr()
window.addstr()
window.attroff()
window.attron()
window.attrset()
window.bkgd()
window.bkgdset()
window.border()
window.box()
window.chgat()
window.clear()
window.clearok()
window.clrtobot()
window.clrtoeol()
window.cursyncup()
window.delch()
window.deleteln()
window.derwin()
window.echochar()
window.enclose()
window.encoding
window.erase()
window.getbegyx()
window.getbkgd()
window.getch()
window.get_wch()
window.getkey()
window.getmaxyx()
window.getparyx()
window.getstr()
window.getyx()
window.hline()
window.idcok()
window.idlok()
window.immedok()
window.inch()
window.insch()
window.insdelln()
window.insertln()
window.insnstr()
window.insstr()
window.instr()
window.is_linetouched()
window.is_wintouched()
window.keypad()
window.leaveok()
window.move()
window.mvderwin()
window.mvwin()
window.nodelay()
window.notimeout()
window.noutrefresh()
window.overlay()
window.overwrite()
window.putwin()
window.redrawln()
window.redrawwin()
window.refresh()
window.resize()
window.scroll()
window.scrollok()
window.setscrreg()
window.standend()
window.standout()
window.subpad()
window.subwin()
window.syncdown()
window.syncok()
window.syncup()
window.timeout()
window.touchline()
window.touchwin()
window.untouchwin()
window.vline()
- Constants
- Functions
curses.textpad
— Text input widget for curses programscurses.ascii
— Utilities for ASCII characterscurses.panel
— A panel stack extension for cursesplatform
— Access to underlying platform’s identifying dataerrno
— Standard errno system symbolserrorcode
EPERM
ENOENT
ESRCH
EINTR
EIO
ENXIO
E2BIG
ENOEXEC
EBADF
ECHILD
EAGAIN
ENOMEM
EACCES
EFAULT
ENOTBLK
EBUSY
EEXIST
EXDEV
ENODEV
ENOTDIR
EISDIR
EINVAL
ENFILE
EMFILE
ENOTTY
ETXTBSY
EFBIG
ENOSPC
ESPIPE
EROFS
EMLINK
EPIPE
EDOM
ERANGE
EDEADLK
ENAMETOOLONG
ENOLCK
ENOSYS
ENOTEMPTY
ELOOP
EWOULDBLOCK
ENOMSG
EIDRM
ECHRNG
EL2NSYNC
EL3HLT
EL3RST
ELNRNG
EUNATCH
ENOCSI
EL2HLT
EBADE
EBADR
EXFULL
ENOANO
EBADRQC
EBADSLT
EDEADLOCK
EBFONT
ENOSTR
ENODATA
ETIME
ENOSR
ENONET
ENOPKG
EREMOTE
ENOLINK
EADV
ESRMNT
ECOMM
EPROTO
EMULTIHOP
EDOTDOT
EBADMSG
EOVERFLOW
ENOTUNIQ
EBADFD
EREMCHG
ELIBACC
ELIBBAD
ELIBSCN
ELIBMAX
ELIBEXEC
EILSEQ
ERESTART
ESTRPIPE
EUSERS
ENOTSOCK
EDESTADDRREQ
EMSGSIZE
EPROTOTYPE
ENOPROTOOPT
EPROTONOSUPPORT
ESOCKTNOSUPPORT
EOPNOTSUPP
EPFNOSUPPORT
EAFNOSUPPORT
EADDRINUSE
EADDRNOTAVAIL
ENETDOWN
ENETUNREACH
ENETRESET
ECONNABORTED
ECONNRESET
ENOBUFS
EISCONN
ENOTCONN
ESHUTDOWN
ETOOMANYREFS
ETIMEDOUT
ECONNREFUSED
EHOSTDOWN
EHOSTUNREACH
EALREADY
EINPROGRESS
ESTALE
EUCLEAN
ENOTNAM
ENAVAIL
EISNAM
EREMOTEIO
EDQUOT
EQFULL
ENOTCAPABLE
ctypes
— A foreign function library for Python- ctypes tutorial
- Loading dynamic link libraries
- Accessing functions from loaded dlls
- Calling functions
- Fundamental data types
- Calling functions, continued
- Calling varadic functions
- Calling functions with your own custom data types
- Specifying the required argument types (function prototypes)
- Return types
- Passing pointers (or: passing parameters by reference)
- Structures and unions
- Structure/union alignment and byte order
- Bit fields in structures and unions
- Arrays
- Pointers
- Type conversions
- Incomplete Types
- Callback functions
- Accessing values exported from dlls
- Surprises
- Variable-sized data types
- ctypes reference
- Finding shared libraries
- Loading shared libraries
- Foreign functions
- Function prototypes
- Utility functions
addressof()
alignment()
byref()
cast()
create_string_buffer()
create_unicode_buffer()
DllCanUnloadNow()
DllGetClassObject()
find_library()
find_msvcrt()
FormatError()
GetLastError()
get_errno()
get_last_error()
memmove()
memset()
POINTER()
pointer()
resize()
set_errno()
set_last_error()
sizeof()
string_at()
WinError()
wstring_at()
- Data types
- Fundamental data types
- Structured data types
- Arrays and pointers
- ctypes tutorial