Skip to content

Instantly share code, notes, and snippets.

@val314159
Created December 14, 2014 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save val314159/3734d87708f1f96c75ed to your computer and use it in GitHub Desktop.
Save val314159/3734d87708f1f96c75ed to your computer and use it in GitHub Desktop.
sets file to nonblocked state. sets process's stdout/stderr to nonblocked state too.
def unblock(f):
"""
sets file to nonblocked state. sets process's stdout/stderr to nonblocked state too.
"""
from subprocess import Popen
if type(p)==Popen:
unblock(p.stderr)
unblock(p.stdout)
return
import os,fcntl
# get the file descriptor
fd = f.fileno()
# get the file's current flag settings
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
# update the file's flags to put the file into non-blocking mode.
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment