distinct fcntl flags for stdin and stdout


M

mbuna

Hello,
when I set non blocking flag with fcntl on sys.stdin, then sys.stdout
turns into non blocking mode too. Is it normal behaviour? How can I
turn stdin into non blocking mode but not stdout? Thanks.

This is a quick program that shows the (my?) problem:

import fcntl
import os
import sys

print "STDIN", sys.stdin, "fd=%d" % sys.stdin.fileno()
print "STDOUT", sys.stdout, "fd=%d" % sys.stdout.fileno()
print "os.O_NDELAY=%04x" % os.O_NDELAY
def state():
flag = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL)
print "stdin: flag=%04x" % flag
flag = fcntl.fcntl(sys.stdout.fileno(), fcntl.F_GETFL)
print "stdout: flag=%04x" % flag
state()
print "setting non blocking on stdin..."
flag = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL)
fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, flag | os.O_NDELAY)
state()
print "removing non blocking on stdin..."
flag = fcntl.fcntl(sys.stdin.fileno(), fcntl.F_GETFL)
fcntl.fcntl(sys.stdin.fileno(), fcntl.F_SETFL, flag & ~os.O_NDELAY)
state()


RESULT
STDIN <open file '<stdin>', mode 'r' at 0x2aaaaaacd120> fd=0
STDOUT <open file '<stdout>', mode 'w' at 0x2aaaaaacd198> fd=1
os.O_NDELAY=0800
stdin: flag=8002
stdout: flag=8002
setting non blocking on stdin...
stdin: flag=8802
stdout: flag=8802
removing non blocking on stdin...
stdin: flag=8002
stdout: flag=8002
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top