Python Glossary Русский

all Python 3statfunction

stat.S_ISSOCK()

file type

Checks from st_mode that the object is a Unix socket, such as a file like /var/run/docker.sock.

Syntax

stat.S_ISSOCK(os.stat(path).st_mode)

A socket file looks like an ordinary name in the directory, but open() cannot open it: you connect to it with socket.AF_UNIX. Test the type with S_ISSOCK, not `mode & stat.S_IFSOCK`: the type bits overlap, and S_IFSOCK contains the bits of S_IFREG and S_IFDIR. Python offers no AF_UNIX on Windows.

Examples

import os, socket, stat
s = socket.socket(socket.AF_UNIX)  # → ? на Windows AF_UNIX нет
s.bind('app.sock')
print(stat.S_ISSOCK(os.stat('app.sock').st_mode))  # → True
s.close()

See also

Open in the full glossarydocs.python.orgReport an inaccuracy