문제

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