misc: update threading monkeypatch for Python 3 (#37986)

This commit is contained in:
Frédéric Péters 2019-11-26 14:51:11 +01:00
parent bc194f23aa
commit bd9d18a7db
1 changed files with 36 additions and 15 deletions

View File

@ -132,26 +132,47 @@ class _MainThread(TenantAwareThread):
self._Thread__delete()
class _DummyThread(TenantAwareThread):
if six.PY2:
class _DummyThread(TenantAwareThread):
def __init__(self):
super(_DummyThread, self).__init__(name=threading._newname("Dummy-%d"))
def __init__(self):
super(_DummyThread, self).__init__(name=threading._newname("Dummy-%d"))
# Thread.__block consumes an OS-level locking primitive, which
# can never be used by a _DummyThread. Since a _DummyThread
# instance is immortal, that's bad, so release this resource.
del self._Thread__block
# Thread.__block consumes an OS-level locking primitive, which
# can never be used by a _DummyThread. Since a _DummyThread
# instance is immortal, that's bad, so release this resource.
del self._Thread__block
self._Thread__started.set()
self._set_ident()
with threading._active_limbo_lock:
threading._active[threading._get_ident()] = self
self._Thread__started.set()
self._set_ident()
with threading._active_limbo_lock:
threading._active[threading._get_ident()] = self
def _set_daemon(self):
return True
def _set_daemon(self):
return True
def join(self, timeout=None):
assert False, "cannot join a dummy thread"
def join(self, timeout=None):
assert False, "cannot join a dummy thread"
else:
class _DummyThread(TenantAwareThread):
def __init__(self):
super(_DummyThread, self).__init__(name=threading._newname("Dummy-%d"), daemon=True)
self._started.set()
self._set_ident()
with threading._active_limbo_lock:
threading._active[self._ident] = self
def _stop(self):
pass
def is_alive(self):
assert not self._is_stopped and self._started.is_set()
return True
def join(self, timeout=None):
assert False, "cannot join a dummy thread"
class AppConfig(django.apps.AppConfig):