object.enable() anti-pattern

Roy Smith roy at panix.com
Fri May 10 01:50:09 EDT 2013


In article <518c7f05$0$29997$c3e8da3$5496439d at news.astraweb.com>,
 Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:

> there is no way to create a C file descriptor in a closed state. Such 
> a thing does not exist. If you have a file descriptor, the file is 
> open. Once you close it, the file descriptor is no longer valid.

Of course there is.

int fd = 37;

I've just created a file descriptor.  There is not enough information 
given to know if it corresponds to an open file or not.

Before you protest that "it's just an int, not a file descriptor", I 
should point out that they're the same thing.  It's pretty common to do 
something like:

for (int fd = 0; fd <= MAX_FD; fd++) {
   close(fd)
}

before forking, to make sure all file descriptors are closed.



More information about the Python-list mailing list