سؤال

What's the inverse of this?

fcntl.fcntl(MyStream.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)

I've tried

fcntl.fcntl(MyStream.fileno(), fcntl.F_SETFL, os.O_BLOCK)

but it results in a AttributeError: 'module' object has no attribute 'O_BLOCK'.

To give a little background, I'm piping data in chunks into STDIN of a popen'ed process. If there is data waiting in STDOUT, I need to read it straight away and pass it back to the client (hence switching to non-blocking). However, when I've finished piping data in, I then need to block until I get an EOF on STDOUT.

If there's a better way to do this (ideally cross-platform?) then I'm all ears

هل كانت مفيدة؟

المحلول

Get the current flag and turn off O_NONBLOCK bit:

flag = fcntl.fcntl(MyStream.fileno(), fcntl.F_GETFL)
fcntl.fcntl(MyStream.fileno(), fcntl.F_SETFL, flag & ~os.O_NONBLOCK)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top