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


Groups > comp.lang.python > #21796 > unrolled thread

Re: Daemonization / Popen / pipe issue

Started byJohn O'Hagan <research@johnohagan.com>
First post2012-03-17 14:37 +1100
Last post2012-03-17 14:37 +1100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Daemonization / Popen / pipe issue John O'Hagan <research@johnohagan.com> - 2012-03-17 14:37 +1100

#21796 — Re: Daemonization / Popen / pipe issue

FromJohn O'Hagan <research@johnohagan.com>
Date2012-03-17 14:37 +1100
SubjectRe: Daemonization / Popen / pipe issue
Message-ID<mailman.748.1331955457.3037.python-list@python.org>
On Fri, 16 Mar 2012 22:12:14 -0400
Lee Clemens <java@leeclemens.net> wrote:


> 
> I have a multi-threaded application, each thread has an instance of a class
> which calls Popen. The command(s) being executed (shell=True) include pipes.
> The errors I have seen involve "broken pipe" and unexepected output (as
> demonstrated in the test case).
> 
> This issues only seem to occur when the application is "daemonized", using a
> double-fork and os.dup2, as shown here:
> http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
> 
> I have provided a test-case here: https://gist.github.com/2054194
> 
> Please test how flipping DAEMONIZE between True and False yield different
> results.


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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web