Skip to content

Instantly share code, notes, and snippets.

@javiermon
Created April 14, 2015 16:40
Show Gist options
  • Select an option

  • Save javiermon/1a08e14b2e972065c79e to your computer and use it in GitHub Desktop.

Select an option

Save javiermon/1a08e14b2e972065c79e to your computer and use it in GitHub Desktop.
set CLOEXEC flag on socket
import fcntl
def set_close_exec(fd):
"""
Helper to add CLOEXEC to provided file descriptor.
:param fd: int
"""
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
fcntl.fcntl(fd, fcntl.F_SETFD, flags | fcntl.FD_CLOEXEC)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment