summaryrefslogtreecommitdiffstats
path: root/Lib/threading.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2011-02-25 22:07:43 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2011-02-25 22:07:43 (GMT)
commit0bd4deba383b1c7f05a4e0c94f1d4b96050a1308 (patch)
treefd95fcfc38af8fceb8e56409f63e4e2bd30e0c52 /Lib/threading.py
parent4bc685752f9f1056545ab121db833a4a68dd794c (diff)
downloadcpython-0bd4deba383b1c7f05a4e0c94f1d4b96050a1308.zip
cpython-0bd4deba383b1c7f05a4e0c94f1d4b96050a1308.tar.gz
cpython-0bd4deba383b1c7f05a4e0c94f1d4b96050a1308.tar.bz2
Issue #6064: Add a `daemon` keyword argument to the threading.Thread
and multiprocessing.Process constructors in order to override the default behaviour of inheriting the daemonic property from the current thread/process.
Diffstat (limited to 'Lib/threading.py')
-rw-r--r--Lib/threading.py21
1 files changed, 7 insertions, 14 deletions
diff --git a/Lib/threading.py b/Lib/threading.py
index fd93f74..cb09afa 100644
--- a/Lib/threading.py
+++ b/Lib/threading.py
@@ -622,7 +622,7 @@ class Thread(_Verbose):
#XXX __exc_clear = _sys.exc_clear
def __init__(self, group=None, target=None, name=None,
- args=(), kwargs=None, verbose=None):
+ args=(), kwargs=None, verbose=None, *, daemon=None):
assert group is None, "group argument must be None for now"
_Verbose.__init__(self, verbose)
if kwargs is None:
@@ -631,7 +631,10 @@ class Thread(_Verbose):
self._name = str(name or _newname())
self._args = args
self._kwargs = kwargs
- self._daemonic = self._set_daemon()
+ if daemon is not None:
+ self._daemonic = daemon
+ else:
+ self._daemonic = current_thread().daemon
self._ident = None
self._started = Event()
self._stopped = False
@@ -648,10 +651,6 @@ class Thread(_Verbose):
self._block.__init__()
self._started._reset_internal_locks()
- def _set_daemon(self):
- # Overridden in _MainThread and _DummyThread
- return current_thread().daemon
-
def __repr__(self):
assert self._initialized, "Thread.__init__() was not called"
status = "initial"
@@ -948,15 +947,12 @@ class _Timer(Thread):
class _MainThread(Thread):
def __init__(self):
- Thread.__init__(self, name="MainThread")
+ Thread.__init__(self, name="MainThread", daemon=False)
self._started.set()
self._set_ident()
with _active_limbo_lock:
_active[self._ident] = self
- def _set_daemon(self):
- return False
-
def _exitfunc(self):
self._stop()
t = _pickSomeNonDaemonThread()
@@ -988,7 +984,7 @@ def _pickSomeNonDaemonThread():
class _DummyThread(Thread):
def __init__(self):
- Thread.__init__(self, name=_newname("Dummy-%d"))
+ Thread.__init__(self, name=_newname("Dummy-%d"), daemon=True)
# Thread._block consumes an OS-level locking primitive, which
# can never be used by a _DummyThread. Since a _DummyThread
@@ -1000,9 +996,6 @@ class _DummyThread(Thread):
with _active_limbo_lock:
_active[self._ident] = self
- def _set_daemon(self):
- return True
-
def join(self, timeout=None):
assert False, "cannot join a dummy thread"