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


Groups > comp.lang.python > #21842

Re: Daemonization / Popen / pipe issue

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <johnmohagan@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'thread,': 0.04; '(python': 0.05; 'exits': 0.07; 'replied': 0.07; 'subject:issue': 0.07; 'threads,': 0.07; 'unexpected': 0.07; 'python': 0.08; 'sockets': 0.09; 'url:github': 0.09; 'broken': 0.12; '"python': 0.15; 'case.': 0.15; 'cleanly': 0.16; 'does,': 0.16; 'multitude': 0.16; 'termination': 0.16; 'waited': 0.16; 'looked': 0.16; 'wrote:': 0.18; 'of.': 0.18; 'issue.': 0.19; '(which': 0.19; "haven't": 0.20; 'header:In-Reply-To:1': 0.22; '(or': 0.22; 'assume': 0.22; 'debian': 0.23; 'sender:addr:gmail.com': 0.24; 'sat,': 0.25; 'saying': 0.26; 'code': 0.26; 'there.': 0.27; 'tried': 0.27; 'fact': 0.27; 'looks': 0.27; 'not.': 0.28; "i'm": 0.28; 'exit': 0.29; 'seem': 0.29; 'pm,': 0.29; 'generally': 0.30; 'received:209.85.210.46': 0.30; 'received:mail- pz0-f46.google.com': 0.30; 'solved': 0.30; 'terminate': 0.30; 'threads': 0.30; 'specifically': 0.30; 'like.': 0.32; 'thread': 0.32; "i've": 0.32; 'that,': 0.32; 'idea': 0.32; 'there': 0.33; 'fri,': 0.34; 'test': 0.34; 'lee': 0.34; 'done': 0.34; 'running': 0.34; 'flag': 0.34; 'yet,': 0.34; 'probably': 0.35; 'to:addr :python-list': 0.35; 'finished': 0.35; 'post': 0.36; 'example,': 0.37; 'executing': 0.37; 'but': 0.37; 'charset:us-ascii': 0.37; 'received:google.com': 0.37; 'similar': 0.37; 'using': 0.37; 'happens': 0.38; 'received:209.85': 0.38; 'references': 0.38; 'data': 0.38; 'recommended': 0.39; 'received:209': 0.39; 'application': 0.40; 'to:addr:python.org': 0.40; 'john': 0.61; 'your': 0.61; 'provided': 0.62; 'header:Message-Id:1': 0.62; 'subject: / ': 0.63; 'cause': 0.67; 'here:': 0.67; 'unnecessary': 0.73; '11:37': 0.84; 'clemens': 0.84; 'execution,': 0.91; 'glance': 0.91; 'interest,': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:subject:message-id:in-reply-to:references :x-mailer:mime-version:content-type:content-transfer-encoding; bh=DpwAGWUxaKxvQ4TMLdKufHyWOE69r5dypu/98gShXVw=; b=P3hJl3VafnyVZlsYZu3hGv+/N+2X1JQy4+WmKE1DRYhUCfFJLXdJ8hTyNUClEVOie6 hITc6Pn3IWnJ4AzwKmcRfNl+/dWPIanST4caAwcS12/ydcIrq0Xbm/f9sBw9T3oenBeQ KPt28BSSFjHI54YEKYd73ohv5QwueVV54FiVVZN/Dx7q9Ob1ewI9CrTBZ4xrpV074kMy 1Cg459h9ItyhKVsBlihuayVg2kZA/HfcJkmeOMcVeeJn+YawBI6En0Hh6o4BDzKc6J/0 GsI4168W+D0AmbGnJLJOMIbk0jkUeLaUITbWbvIGwDdKu26Vxd80xn2ICFyxu2C0S3LF x5dw==
Sender "John O'Hagan" <johnmohagan@gmail.com>
Date Sun, 18 Mar 2012 12:35:16 +1100
From John O'Hagan <research@johnohagan.com>
To python-list@python.org
Subject Re: Daemonization / Popen / pipe issue
In-Reply-To <4F650D66.4040209@leeclemens.net>
References <4F63F2FE.1030409@leeclemens.net> <20120317143726.7134d2b04d56d1759d8eeeb6@johnohagan.com> <4F650D66.4040209@leeclemens.net>
X-Mailer Sylpheed 3.2.0beta6 (GTK+ 2.24.10; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.771.1332034527.3037.python-list@python.org> (permalink)
Lines 59
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1332034527 news.xs4all.nl 6972 [2001:888:2000:d::a6]:41889
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:21842

Show key headers only | View raw


On Sat, 17 Mar 2012 18:17:10 -0400
Lee Clemens <java@leeclemens.net> wrote:

> On 03/16/2012 11:37 PM, John O'Hagan wrote:
> > On Fri, 16 Mar 2012 22:12:14 -0400
> > Lee Clemens <java@leeclemens.net> wrote:
> >
> >> I have a multi-threaded application
> >>
> >> I have provided a test-case here: https://gist.github.com/2054194
> > I haven't looked at your test case yet, but a possible cause is the fact
> > that the main application (or main thread) exits if it has finished
> > executing and only daemon threads remain. This can  abruptly terminate
> > threads which may be busy, for example, communicating via a pipe. The best
> > solution IMO is not to use daemon threads, but to give all threads a way to
> > terminate cleanly before the main thread does, even if this means using a
> > flag or the like.
> >
> > HTH,
> >
> > John
> >
> I call .join() on each spawned thread, whether it is daemonized or not.
> The code is available here:
> 
> https://gist.github.com/2054194

I've tried running your code (which at a glance looks very well-written) but I
get the broken pipe errors whether the DAEMONIZE flag is True or False
(Python 2.7, Debian testing). I don't have time to dig much deeper. 

> Is it generally not recommended to daemonize Python applications using
> this method? 

I'm no guru, but not that I know of. I haven't seen the os.fork method you use
before; out of interest, why not use Thread.setDaemon? 

> Do you have any references or data to support your opinion?
> Do you have any references which specifically state - "Daemonizing
> Python applications cause Python to work in unexpected ways."? 

Not particularly, although there are a few oldish references to "Python daemon
threads considered harmful" out there. You probably know that daemonising can
cover a multitude of sins, and it's always a good idea to ensure clean
termination and not just assume that what happens in a daemon thread on program
exit is moot. I'm not saying you haven't done that, in fact your errors seem to
occur during execution, not termination.

I replied to your post because I've had broken pipe errors before with
daemon threads communicating on sockets which sounded similar to your issue. I
solved them by rewriting so that the main thread told the threads to terminate,
and waited till they had. This made daemonising unnecessary in that case.


[...]

Regards,

John

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


Thread

Re: Daemonization / Popen / pipe issue John O'Hagan <research@johnohagan.com> - 2012-03-18 12:35 +1100

csiph-web