Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set blocking I/O flags for FreeBSD #954

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions click/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,12 @@ def is_bytes(x):
# available (which is why we use try-catch instead of the WIN variable
# here), such as the Google App Engine development server on Windows. In
# those cases there is just nothing we can do.
def set_binary_mode(f):
return f

try:
import msvcrt
except ImportError:
set_binary_mode = lambda x: x
else:

def set_binary_mode(f):
try:
fileno = f.fileno()
Expand All @@ -178,6 +179,23 @@ def set_binary_mode(f):
else:
msvcrt.setmode(fileno, os.O_BINARY)
return f
except ImportError:
pass

try:
import fcntl

def set_binary_mode(f):
try:
fileno = f.fileno()
except Exception:
pass
else:
flags = fcntl.fcntl(fileno, fcntl.F_GETFL)
fcntl.fcntl(fileno, fcntl.F_SETFL, flags & ~os.O_NONBLOCK)
return f
except ImportError:
pass

def isidentifier(x):
return _identifier_re.search(x) is not None
Expand Down