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


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

forking and avoiding zombies!

Started byandrea crotti <andrea.crotti.0@gmail.com>
First post2012-12-10 15:42 +0000
Last post2012-12-10 15:42 +0000
Articles 1 — 1 participant

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


Contents

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

#34548 — forking and avoiding zombies!

Fromandrea crotti <andrea.crotti.0@gmail.com>
Date2012-12-10 15:42 +0000
Subjectforking and avoiding zombies!
Message-ID<mailman.676.1355154162.29569.python-list@python.org>
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

[toc] | [standalone]


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


csiph-web