Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #72220

Re: daemon thread cleanup approach

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <cameron@cskk.homeip.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'anyway.': 0.05; 'init': 0.07; 'caller': 0.09; 'exit': 0.09; 'function,': 0.09; 'properly.': 0.09; 'bug': 0.12; 'assume': 0.14; 'thread': 0.14; 'windows': 0.15; '>does': 0.16; 'c-level': 0.16; 'caller.': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:cskk.homeip.net': 0.16; 'received:homeip.net': 0.16; 'simpson': 0.16; 'thread,': 0.16; 'timeout': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'library': 0.18; 'header:User- Agent:1': 0.23; 'cheers,': 0.24; 'least': 0.26; '(for': 0.26; 'header:In-Reply-To:1': 0.27; 'external': 0.29; "doesn't": 0.30; "i'm": 0.30; 'asks': 0.31; 'routine': 0.31; 'anyone': 0.31; 'probably': 0.32; 'problem': 0.35; 'case,': 0.35; 'there': 0.35; 'charset:us-ascii': 0.36; 'possible': 0.36; 'ends': 0.38; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'ensure': 0.60; 'even': 0.60; 'disclaimer:': 0.60; 'simply': 0.61; 'content-disposition:inline': 0.62; 'chance': 0.65; 'occur': 0.65; 'hang': 0.67; 'sound': 0.68; 'safe': 0.72; 'banks': 0.74; 'case?': 0.84; 'received:192.168.15': 0.84
Date Thu, 29 May 2014 16:07:37 +1000
From Cameron Simpson <cs@zip.com.au>
To python-list@python.org
Subject Re: daemon thread cleanup approach
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Disposition inline
In-Reply-To <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com>
User-Agent Mutt/1.5.21 (2010-09-15)
References <368aec88-ebe9-4da0-a537-92ff9b690647@googlegroups.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.10439.1401343667.18130.python-list@python.org> (permalink)
Lines 19
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1401343667 news.xs4all.nl 2923 [2001:888:2000:d::a6]:41676
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:72220

Show key headers only | View raw


On 28May2014 18:20, Carl Banks <pavlovevidence@gmail.com> wrote:
>Here's the solution I came up with: in the library's init function, it will start a non-daemon thread that simply joins the main thread, and then asks all existing worker threads to exit gracefully before timing out and leaving them to be killed.  So if an exception ends the main thread, there is still a chance to clean up properly.
>
>Does anyone see a potential problem with this approach?  It it possible that this will cause the program to hang in any case?  We can assume that all calls to the library will occur from the main thread, or at least from the same thread.  (If that isn't the case, then the caller has taken responsibility to ensure the program doesn't hang.)

That sounds safe to me, unless any of the subthreads call some C-level library 
routine that hangs even in a daemon thread. Which I assume either isn't the 
case or isn't a bug addressable this way anyway.

That's probably the best you can do from the sound of it, given that you may 
not hang (for longer than your timeout choice) and the calls are all at the 
whim of an external caller.

BTW, what were your dislikes of the with statement?

Disclaimer: I'm not a Windows guy.

Cheers,
Cameron Simpson <cs@zip.com.au>

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

daemon thread cleanup approach Carl Banks <pavlovevidence@gmail.com> - 2014-05-28 18:20 -0700
  Re: daemon thread cleanup approach Miki Tebeka <miki.tebeka@gmail.com> - 2014-05-28 22:51 -0700
  Re: daemon thread cleanup approach Cameron Simpson <cs@zip.com.au> - 2014-05-29 16:07 +1000
  Re: daemon thread cleanup approach Chris Angelico <rosuav@gmail.com> - 2014-05-29 18:15 +1000
    Re: daemon thread cleanup approach Carl Banks <pavlovevidence@gmail.com> - 2014-05-29 12:40 -0700
  Re: daemon thread cleanup approach Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-05-30 13:47 -0700
  Re: daemon thread cleanup approach Ethan Furman <ethan@stoneleaf.us> - 2014-05-30 13:59 -0700
  Re: daemon thread cleanup approach Devin Jeanpierre <jeanpierreda@gmail.com> - 2014-05-30 14:58 -0700

csiph-web