Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daemonic processes are not allowed to have children #211

Closed
yannpom opened this issue Dec 5, 2016 · 2 comments
Closed

daemonic processes are not allowed to have children #211

yannpom opened this issue Dec 5, 2016 · 2 comments

Comments

@yannpom
Copy link
Contributor

yannpom commented Dec 5, 2016

Hello,

First, thank you for this project, Celery was too complex for my use case and I wanted to use Django's database as the broker. So far I'm very happy with django-q.

But I got one problem: I have a task spawning some child processes using multiprocessing.Process but it fails to run asynchronously using django-q with the following error:

daemonic processes are not allowed to have children

This is because the workers are started with daemon = True in cluster.py:148

If I add daemon = False as shown here:

    def spawn_process(self, target, *args):
        """
        :type target: function or class
        """
        p = Process(target=target, args=args)
        p.daemon = True
        if target == worker:
            p.daemon = False         # <=== LINE ADDED HERE ======
            p.timer = args[2]
            self.pool.append(p)
        p.start()
        return p

Everything works and I can start child processes in my task.

So I was wondering what are the consequences? I could not notice any change in the behaviour of django-q, it may be related to process termination and orphaned children as the multiprocessing documentation would suggest HERE.
But I tried to stop my qcluster while a task was ongoing, and everything works as expected. The qcluster stops after the task has terminated.

In what scenario changing Daemon to False would cause a problem?

@Koed00
Copy link
Owner

Koed00 commented Dec 5, 2016

I set it up so when the stop signal is sent, each worker is politely asked to finish its work and then exit. This will safely deal with the child processes you are spawning.
They would be orphaned however if the any of the main processes are terminated without being able to complete the stop sequence. ie. forced termination by the server.

I guess we could add an option to un-daemonize the workers , for those that require it and understand the consequences.

@yannpom
Copy link
Contributor Author

yannpom commented Dec 5, 2016

Thanks for your reply. I see how that could result in orphaned child process, but I'm willing to take the limited risk.
I proposed the pull request #212
But I won't feel offended if you don't accept it don't worry, I'm already using my fork.

@yannpom yannpom closed this as completed Dec 5, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants