Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.029 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'subject:file': 0.07; 'ignoring': 0.09; 'thread': 0.10; '"python': 0.16; '(inclusive)': 0.16; 'behold,': 0.16; 'descriptors': 0.16; 'googling': 0.16; "guido's": 0.16; 'number?': 0.16; 'skip': 0.18; 'machine': 0.21; 'module': 0.23; 'header:In-Reply-To:1': 0.24; 'dance': 0.27; 'errors.': 0.27; 'message-id:@mail.gmail.com': 0.28; 'subject:/': 0.29; '(new': 0.29; 'returned': 0.32; 'open': 0.33; '(for': 0.34; 'weeks': 0.34; 'file': 0.34; 'received:google.com': 0.34; 'to:addr :python-list': 0.35; 'skip:o 20': 0.35; 'but': 0.36; '(and': 0.36; 'basic': 0.36; 'child': 0.36; 'subject:: ': 0.37; 'wanted': 0.39; 'to:addr:python.org': 0.39; 'sure': 0.40; 'some': 0.40; 'close': 0.61; 'today': 0.64; 'different': 0.64; 'discover': 0.73; 'subject: & ': 0.73; 'to:name:python': 0.84 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:to :content-type; bh=wjKvBcofQb1ZrBv+JBrLVBnfl8ZUOM3Ih1p0DLIFB+A=; b=a6QFLLYQCAqQeGq9xSmsufdNJhVFeJRUhTSPKZT5P07WUUHsfks1kNknqkwLxWqPqN XFjd3wAMX+VBqSi3aaRVBSu/AidOUt1aDor77cGGO7w7F/PRlqpbXpjQh4/xFu6q3Jjk 3s0QFjyJ80/e/YEG8um+WZ9lk0fJvL1Lqta5JLF9HfklTXH/I8K8cHWog950PnPFd+3s AZRABC/my4jotLugaGFwIR8KcoPmu2aceqrxUlnwlZR75vsOA4VZ5xXmFwPsJRszE3WH kUl1nprfQ6mLmDrGQAf+VXH16TdPCdUQaeIwIwKj6rzIB1CVN29a2v7VTFvlV+Vd0m/B mhyA== MIME-Version: 1.0 X-Received: by 10.60.74.34 with SMTP id q2mr4774771oev.68.1433253534523; Tue, 02 Jun 2015 06:58:54 -0700 (PDT) In-Reply-To: References: Date: Tue, 2 Jun 2015 08:58:54 -0500 Subject: Re: fork/exec & close file descriptors From: Skip Montanaro To: 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: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1433253538 news.xs4all.nl 2867 [2001:888:2000:d::a6]:42693 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 3864 X-Received-Body-CRC: 559895122 Xref: csiph.com comp.lang.python:91839 Reviving (and concluding) a thread I started a couple weeks ago, I asked: > The basic fork/exec dance is not a problem, but how do I discover > all the open file descriptors in the new child process to make sure > they get closed? Do I simply start at fd 3 and call os.close() on > everything up to some largish fd number? I wanted this again today (for different reasons than before). Googling for "python close all file descriptors" returned the os module docs as the first hit, and lo and behold, what do I see documented? os.closerange (new in 2.6): os.closerange(fd_low, fd_high) Close all file descriptors from fd_low (inclusive) to fd_high (exclusive), ignoring errors. Guido's time machine strikes again... Skip