Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed4a.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.026 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'socket': 0.07; 'cleanup': 0.09; 'tcp/ip': 0.09; 'terminates': 0.09; 'windows,': 0.09; 'cc:addr:python-list': 0.11; 'suggest': 0.14; 'windows': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'imo,': 0.16; 'mean,': 0.16; 'sockets': 0.16; 'tcp': 0.16; 'temp': 0.16; 'unexpected': 0.16; 'wrote:': 0.18; 'library': 0.18; 'server,': 0.19; 'thu,': 0.19; 'putting': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; '(such': 0.24; 'certainly': 0.24; 'passes': 0.24; 'cc:2**0': 0.24; 'possibly': 0.26; 'header:In- Reply-To:1': 0.27; '(this': 0.29; 'am,': 0.29; 'room': 0.29; 'unix': 0.29; 'waste': 0.30; 'message-id:@mail.gmail.com': 0.30; 'delayed': 0.31; 'pipe': 0.31; 'probably': 0.32; 'themselves': 0.32; 'up.': 0.33; "can't": 0.35; 'connection': 0.35; 'knows': 0.35; 'problem.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'building': 0.35; 'there': 0.35; 'done': 0.36; 'should': 0.36; 'too': 0.37; 'requirements': 0.37; 'being': 0.38; 'remote': 0.38; 'server': 0.38; 'bringing': 0.38; 'easiest': 0.38; 'that,': 0.38; 'does': 0.39; 'how': 0.40; 'even': 0.60; 'deleting': 0.60; 'most': 0.60; 'matter': 0.61; "you're": 0.61; 'temporary': 0.65; 'hang': 0.67; 'believe': 0.68; 'busy.': 0.68; 'notices': 0.68; 'banks': 0.74; 'gone.': 0.84; "it'd": 0.84; 'killing': 0.84; 'precious': 0.84; 'spawned': 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=O71VWLbQWDH23o7+xQ1O6LyZSCLXf3igX5VAIvN1qjg=; b=gfT6ZRrRhCdLoE2dQhTWy+Vamr5h0Oyqysmjd3cG9wgpib51jP2Fi3xeuQ6+r2aUQf pqcMnXi+V+fJvQjaOVES4pWW99FSkXa3641Y9djEVRc6gvkaqZtB7Z51Y0ehVLF5D8/r z8WhKzBP7ZTZvWdRuXpuhev7nM/bSYSUDypYatbozQXMPrMidy50JDBMYxeo62Ayi75a nl3VRTJVgMT5lFhHAPFnfA7mUQiD8XJIK4CoFBMen7qXf2DqBmj6SaClxbEtY8Fs3H/6 t2E70znyXjqboDe9L70IYR/rKTtaPdsSTWP7MSrNfSKvOQYxxq93+nUZsKmIXleuN082 eTcg== MIME-Version: 1.0 X-Received: by 10.220.81.194 with SMTP id y2mr4846114vck.29.1401351335805; Thu, 29 May 2014 01:15:35 -0700 (PDT) In-Reply-To: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> References: <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com> Date: Thu, 29 May 2014 18:15:35 +1000 Subject: Re: daemon thread cleanup approach From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1401351344 news.xs4all.nl 2971 [2001:888:2000:d::a6]:39052 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72228 On Thu, May 29, 2014 at 11:20 AM, Carl Banks wrote: > Most threads have cleanup work to do (such as deleting temporary directories and killing spawned processes). > > For better or worse, one of the requirements is that the library can't cause the program to hang no matter what... This ma y be a fundamental problem. I don't know how Windows goes with killing processes (can that ever hang?), but certainly you can get unexpected delays deleting a temp dir, although it would probably require some deliberate intervention, like putting your %temp% on a remote drive and then bringing that server down. But believe you me, if there is a stupid way to do something, someone WILL have done it. (Have you ever thought what it'd be like to have your swapfile/pagefile on a network drive? I mean, there's acres of room on the server, why waste some of your precious local space?) So you may want to organize this as a separate spin-off process that does the cleaning up. That way, the main process has completely ended, but the cleanup daemon is still busy. And if you're going to do that, then the easiest way, IMO, would be to have your worker threads be themselves in a separate process; your library passes work across to this other process via a pipe or socket (this being Windows, that would have to be a TCP socket, not a Unix domain socket, but a named pipe would also work), and when the pipe/socket connection is broken, the other end knows that it should clean up. That way, you get to clean up perfectly even if the process terminates abruptly (segfault, system kill, whatever), although possibly delayed until the system notices that the other end is gone. ChrisA (sometimes I feel I suggest TCP/IP sockets the way Grant Imahara suggests building a robot... enthusiastically and maaaaaybe too often)