1

I want to start a daemon process using multiprocessing exiting the main thread. I wrote this code:

import multiprocessing as mp
from time import sleep

def mytarget():
    while True:
        print "yes"
        sleep(1)

process = mp.Process(target=mytarget)
process.daemon = True
process.start()

But the daemon process doesn't appear. I know I can solve it using os.fork like this:

import os
from time import sleep

def mytarget():
    while True:
        print "yes"
        sleep(1)

pid = os.fork()
if pid == 0:
    mytarget()

But it's not supported in Windows. So I need a solution for multiprocessing module. Thanks!

Fomalhaut
  • 8,590
  • 8
  • 51
  • 95
  • The multiprocessing module is not meant for this. Use a library for creating daemons or services. I can recommend the [`service` package](http://python-service.readthedocs.io/en/latest/). – MisterMiyagi Nov 20 '16 at 12:21
  • Does this answer your question? [How to start daemon process from python on windows?](https://stackoverflow.com/questions/12843903/how-to-start-daemon-process-from-python-on-windows) – user202729 Aug 05 '22 at 03:16

1 Answers1

0

Looking through PyPyi there are quite a few solutions, e.g. py_daemoniker.

dav1d
  • 5,917
  • 1
  • 33
  • 52