Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Marko Rauhamaa Newsgroups: comp.lang.python Subject: Re: fork/exec & close file descriptors Date: Wed, 03 Jun 2015 17:49:23 +0300 Organization: A noiseless patient Spider Lines: 21 Message-ID: <87egls4zkc.fsf@elektro.pacujo.net> References: <87pp5eksnc.fsf@universite-de-strasbourg.fr.invalid> <87eglt7u5i.fsf@elektro.pacujo.net> <87lhg1lt00.fsf@universite-de-strasbourg.fr.invalid> <87a8wh7nq6.fsf@elektro.pacujo.net> <87d21dl0jc.fsf@universite-de-strasbourg.fr.invalid> <877frl6xxj.fsf@elektro.pacujo.net> <556eee15$0$12975$c3e8da3$5496439d@news.astraweb.com> <874mmp5654.fsf@elektro.pacujo.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="b7cb1518d23ec19d482dcc9c31d30fdd"; logging-data="11297"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/48bnhwsv5nml4GIg06G2" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:RY6EOQuwyGNf1P0lY9RWxooTlTs= sha1:2PDYNFhNZajcD22phIzVJN+NBdM= Xref: csiph.com comp.lang.python:91970 alister : > I meant the program that is supplying your app with file handles > willy- nilly without caring what happens to them You seem to be advocating a strategy whereby the application keeps close track of all file descriptors and closes them individually as needed. Thing is, processes can be forked by library calls. For example, you might have developed a class that converts a synchronous database API into an asynchronous one. You'll have your object fork a helper process that makes blocking calls while the object methods make sure never to block the caller. The application doesn't know the library would be starting a child process. On the other hand, the library has no idea on what files the application might have open. That's why the library traverses all file descriptors and closes them categorically after forking. Marko