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


Groups > comp.lang.python > #34548

forking and avoiding zombies!

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <andrea.crotti.0@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'received:209.85.223': 0.03; '"""': 0.05; 'decorator': 0.07; '**kwargs)': 0.09; '**kwargs):': 0.09; 'fork': 0.09; 'spawn': 0.09; 'def': 0.10; 'to:name:python-list': 0.15; 'daemon,': 0.16; 'it..': 0.16; 'reproduce': 0.16; 'subject:avoiding': 0.16; 'import': 0.21; 'runs': 0.22; 'skip:_ 20': 0.22; 'implemented': 0.27; 'easiest': 0.27; 'message-id:@mail.gmail.com': 0.27; 'run': 0.28; 'skip:_ 10': 0.29; 'function': 0.30; 'code': 0.31; 'problem': 0.33; 'to:addr:python-list': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'thanks': 0.34; 'process,': 0.35; 'received:209.85': 0.35; 'but': 0.36; 'wanted': 0.36; 'method': 0.36; 'possible': 0.37; 'received:209': 0.37; 'skip:o 20': 0.38; 'gives': 0.39; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'end': 0.40; 'back': 0.62; 'perfect': 0.63; 'below.': 0.68
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=+lyA5qDdqHbyhsBQ8laY5igvpN9xUBaxFOx2t+4glvU=; b=JJme/hAZJYVNjMyHhycfz4rVvohfAJEbGOJVceg7sA8HXQth5qYM7f1MixwXHkgi+I 30pEQZOCR6EvQf3NuPa2cEG8+uLv1FumxSTFMcfqBGcoeURS/E75mmQXcxRZ2s8GJiVh c8v2e9oE5GFLUycri9tvGzEJq8Ukslg5h51jH4gm4rlYCuX6IgmUhKrIvx9UHWYp+0cs 3/sl+MC1KFxxvCGksl87Xx5FscJ4R7lj/pbQKS7pQzCN+Ov+I1F9WRryFOEmZweLakBW bMeOq1SgZ0jWhBThC39+6pmTITTcz2MmJy9n7sghxvkMY9DJenpqYEAbJovk++SVqNzh GNxw==
MIME-Version 1.0
Date Mon, 10 Dec 2012 15:42:39 +0000
Subject forking and avoiding zombies!
From andrea crotti <andrea.crotti.0@gmail.com>
To python-list <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
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 <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.676.1355154162.29569.python-list@python.org> (permalink)
Lines 30
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1355154162 news.xs4all.nl 6972 [2001:888:2000:d::a6]:34788
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:34548

Show key headers only | View raw


So I implemented a simple decorator to run a function in a forked
process, as below.

It works well but the problem is that the childs end up as zombies on
one machine, while strangely
I can't reproduce the same on mine..

I know that this is not the perfect method to spawn a daemon, but I
also wanted to keep the code
as simple as possible since other people will maintain it..

What is the easiest solution to avoid the creation of zombies and
maintain this functionality?
thanks


def on_forked_process(func):
    from os import fork
    """Decorator that forks the process, runs the function and gives
    back control to the main process
    """
    def _on_forked_process(*args, **kwargs):
        pid = fork()
        if pid == 0:
            func(*args, **kwargs)
            _exit(0)
        else:
            return pid

    return _on_forked_process

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


Thread

forking and avoiding zombies! andrea crotti <andrea.crotti.0@gmail.com> - 2012-12-10 15:42 +0000

csiph-web