def set_socket_inherit(sock, inherit):
 try:
  if iswindows:
   import win32api, win32con
   if inherit:
    flags = win32con.HANDLE_FLAG_INHERIT
   else:
    flags = 0
   win32api.SetHandleInformation(sock.fileno(), win32con.HANDLE_FLAG_INHERIT, flags)
  else:
   import fcntl
   fd = sock.fileno()
   flags = (fcntl.fcntl(fd, fcntl.F_GETFD) & (~ fcntl.FD_CLOEXEC))
   if (not inherit):
    flags = (flags | fcntl.FD_CLOEXEC)
   fcntl.fcntl(fd, fcntl.F_SETFD, flags)
 except:
  import traceback
  traceback.print_exc()

def set_socket_inherit ( sock , inherit ) : try : if iswindows : import win32api , win32con if inherit : flags = win32con . HANDLE_FLAG_INHERIT else : flags = 0 win32api . SetHandleInformation ( sock . fileno ( ) , win32con . HANDLE_FLAG_INHERIT , flags ) else : import fcntl fd = sock . fileno ( ) flags = ( fcntl . fcntl ( fd , fcntl . F_GETFD ) & ( ~ fcntl . FD_CLOEXEC ) ) if ( not inherit ) : flags = ( flags | fcntl . FD_CLOEXEC ) fcntl . fcntl ( fd , fcntl . F_SETFD , flags ) except : import traceback traceback . print_exc ( )
mark a socket as inheritable or non-inheritable to child processes .