Index: Doc/library/multiprocessing.rst =================================================================== --- Doc/library/multiprocessing.rst (revision 83065) +++ Doc/library/multiprocessing.rst (working copy) @@ -295,7 +295,7 @@ :class:`Process` and exceptions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. class:: Process([group[, target[, name[, args[, kwargs]]]]]) +.. class:: Process([group[, target[, name[, args[, kwargs[, daemon]]]]]]) Process objects represent activity that is run in a separate process. The :class:`Process` class has equivalents of all the methods of @@ -310,9 +310,13 @@ :sub:`1`,N\ :sub:`2`,...,N\ :sub:`k` is a sequence of integers whose length is determined by the *generation* of the process. *args* is the argument tuple for the target invocation. *kwargs* is a dictionary of keyword - arguments for the target invocation. By default, no arguments are passed to - *target*. + arguments for the target invocation. *daemon* sets the process + :attr:`daemon` flag to ``True`` or ``False``. If ``None`` is explicitly + provided this flag will be inherited from the creating process. + The default value for *daemon* is False. + By default, no arguments are passed to *target*. + If a subclass overrides the constructor, it must make sure it invokes the base class constructor (:meth:`Process.__init__`) before doing anything else to the process. Index: Lib/multiprocessing/process.py =================================================================== --- Lib/multiprocessing/process.py (revision 83065) +++ Lib/multiprocessing/process.py (working copy) @@ -59,18 +59,23 @@ class Process(object): ''' - Process objects represent activity that is run in a separate process + Process objects represent activity that is run in a separate process. - The class is analagous to `threading.Thread` + The class is analagous to ``threading.Thread``. ''' _Popen = None - def __init__(self, group=None, target=None, name=None, args=(), kwargs={}): + def __init__(self, group=None, target=None, name=None, args=(), kwargs={}, + daemon=False): assert group is None, 'group argument must be None for now' count = next(_current_process._counter) self._identity = _current_process._identity + (count,) self._authkey = _current_process._authkey self._daemonic = _current_process._daemonic + if daemon is not None: + self._daemonic = daemon + else: + self._daemonic = _current_process._daemonic self._tempdir = _current_process._tempdir self._parent_pid = os.getpid() self._popen = None Index: Lib/test/test_multiprocessing.py =================================================================== --- Lib/test/test_multiprocessing.py (revision 83065) +++ Lib/test/test_multiprocessing.py (working copy) @@ -151,6 +151,21 @@ self.assertEqual(current.ident, os.getpid()) self.assertEqual(current.exitcode, None) + def test_daemon_keyword_argument(self): + if self.TYPE == "threads": + return + + proc0 = self.Process(target=self._test) + self.assertFalse(proc0.daemon) + proc1 = self.Process(target=self._test, daemon=True) + self.assertTrue(proc1.daemon) + proc2 = self.Process(target=self._test, daemon=False) + self.assertFalse(proc2.daemon) + + # By default uses the current process's daemon flag. + proc3 = self.Process(target=self._test) + self.assertEquals(proc3.daemon, self.current_process().daemon) + def _test(self, q, *args, **kwds): current = self.current_process() q.put(args)