Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:file': 0.07; 'pep': 0.09; 'restart': 0.09; 'skip:/ 10': 0.09; 'yeah,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'c/c++': 0.16; 'descriptors': 0.16; 'enough.': 0.16; 'fds': 0.16; 'fork': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'sane': 0.16; 'underlying': 0.16; 'files.': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'cc:addr:python.org': 0.22; 'necessary.': 0.24; 'skip': 0.24; 'cc:2**0': 0.24; 'possibly': 0.26; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'compared': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'flags': 0.31; 'though.': 0.31; 'file': 0.32; 'option': 0.32; 'open': 0.33; 'linux': 0.33; "can't": 0.35; 'created': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'useful': 0.36; 'should': 0.36; 'files': 0.38; 'pm,': 0.38; 'use.': 0.39; 'how': 0.40; 'tell': 0.60; 'back': 0.62; 'guarantee': 0.63; 'become': 0.64; 'between': 0.67; 'subject: & ': 0.68; '11:44': 0.84; '2015': 0.84; 'pocket': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=k8KtAfr3V91JYF5Xwup5+cojgTrgSKa39VgMqJKoOSQ=; b=vbGUdU5lN22lAf14vmSyQvMRwv1mFPtGK9ae2vYaiu1c+T3yU5RCrx5eMJY5gIUbQ0 sbCyz20XhZB3FUbVEInF0V2+DMSM4OfjxBWmFAYRcojljlgZy1Pw4g7+oEq0T+S4Xyd6 x1rALwWcmWPEcVo//NRsjLhAQnl3eZZ5ExIj2b0tWYG2PN6BPCQkp29dCLhcAtMhwiqN hng2XPXLF1eABTbv825CeGwhG0jCRZa4VMRSQJnExqYnbkZuKZE7DjzdhypA0EUgLt+z Qi2W3jZua3l2AjoMFD+zKQJTzI3zMnbnHrg6GibB/PAikZnosLhNPGSG3sHyT22mb1F2 dtxA== MIME-Version: 1.0 X-Received: by 10.43.0.67 with SMTP id nl3mr18990643icb.59.1432043677316; Tue, 19 May 2015 06:54:37 -0700 (PDT) In-Reply-To: References: Date: Tue, 19 May 2015 23:54:37 +1000 Subject: Re: fork/exec & close file descriptors From: Chris Angelico Cc: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432043685 news.xs4all.nl 2867 [2001:888:2000:d::a6]:41586 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:90855 On Tue, May 19, 2015 at 11:44 PM, Skip Montanaro wrote: > > On Tue, May 19, 2015 at 8:33 AM, Chris Angelico wrote: >> >> What Python version are you targeting? Are you aware of PEP 446? > > > Yeah, I'm still on 2.7, and am aware of PEP 446. Note that many of the file > descriptors will not have been created by my Python code. They will have > been created by underlying C/C++ libraries, so I can't guarantee which flags > were set on file open. > > I'm going to continue to pursue solutions which won't require a restart for > now, but would like to have a sane restart option in my back pocket should > it become necessary. Fair enough. What you MAY be able to do is preempt it by going through your FDs and setting them all CLOEXEC, but it won't make a lot of difference compared to just going through them all and closing them between fork and exec. On Linux (and possibly some other Unixes), /proc/self/fd may be of use. Enumerating files in that should tell you about your open files. How useful that is I don't know, though. ChrisA