[Python-ideas] Tulip / PEP 3156 - subprocess events

Oleg Broytman phd at phdru.name
Fri Jan 18 22:37:34 CET 2013


On Sat, Jan 19, 2013 at 01:25:31AM +0400, Oleg Broytman <phd at phdru.name> wrote:
> On Fri, Jan 18, 2013 at 09:01:32PM +0000, Paul Moore <p.f.moore at gmail.com> wrote:
> > Hmm, I'm looking at a pipe transport on Unix, and I find I don't know
> > enough about programming Unix. How do I set a file descriptor
> > (specifically a pipe) in Unix to be nonblocking? For a socket,
> > sock.setblocking(False) does the job. But for a pipe/file, the only
> > thing I can see is the O_NONBLOCK flag to os.open/os.pipe2. Is it not
> > possible to set an already open file descriptor to be nonblocking?
>> F_GETFL
> Read the file descriptor's flags.
> F_SETFL
> Set the file status flags part of the descriptor's flags to the
> value specified by arg. Remaining bits (access mode, file creation
> flags) in arg are ignored. On Linux this command can only change the
> O_APPEND, O_NONBLOCK, O_ASYNC, and O_DIRECT flags.

 So you have to call fnctl() on the pipe's descriptor to F_GETFL
flags, set O_NONBLOCK and call fnctl() to F_SETFL the new flags back.
Oleg.
-- 
 Oleg Broytman http://phdru.name/ phd at phdru.name
 Programmers don't die, they just GOSUB without RETURN.


More information about the Python-ideas mailing list

AltStyle によって変換されたページ (->オリジナル) /