Merge branch '1210' into v0.6

This commit is contained in:
Peter Šurda 2018-04-10 13:47:25 +02:00
commit 2de5fbe01a
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87

View File

@ -1,9 +1,18 @@
"""Helper threading perform all the threading operations."""
from contextlib import contextmanager from contextlib import contextmanager
import threading import threading
try: try:
import prctl import prctl
def set_thread_name(name): prctl.set_name(name) except ImportError:
def set_thread_name(name):
"""Set the thread name for external use (visible from the OS)."""
threading.current_thread().name = name
else:
def set_thread_name(name):
"""Set a name for the thread for python internal use."""
prctl.set_name(name)
def _thread_name_hack(self): def _thread_name_hack(self):
set_thread_name(self.name) set_thread_name(self.name)
@ -11,8 +20,7 @@ try:
threading.Thread.__bootstrap_original__ = threading.Thread._Thread__bootstrap threading.Thread.__bootstrap_original__ = threading.Thread._Thread__bootstrap
threading.Thread._Thread__bootstrap = _thread_name_hack threading.Thread._Thread__bootstrap = _thread_name_hack
except ImportError:
def set_thread_name(name): threading.current_thread().name = name
class StoppableThread(object): class StoppableThread(object):
def initStop(self): def initStop(self):
@ -23,6 +31,7 @@ class StoppableThread(object):
self._stopped = True self._stopped = True
self.stop.set() self.stop.set()
class BusyError(threading.ThreadError): class BusyError(threading.ThreadError):
pass pass