This repository has been archived on 2024-12-24. You can view files and clone it, but cannot push or open issues or pull requests.
PyBitmessage-2024-12-24/src/helper_threading.py
Peter Surda 4536e44b8c
Thread names propagate to system
- the thread names should now show up in the monitoring tools of
operating systems (tested on linux)
2017-07-06 19:35:40 +02:00

24 lines
714 B
Python

import threading
try:
import prctl
def set_thread_name(name): prctl.set_name(name)
def _thread_name_hack(self):
set_thread_name(self.name)
threading.Thread.__bootstrap_original__(self)
threading.Thread.__bootstrap_original__ = threading.Thread._Thread__bootstrap
threading.Thread._Thread__bootstrap = _thread_name_hack
except ImportError:
log('WARN: prctl module is not installed. You will not be able to see thread names')
def set_thread_name(name): pass
class StoppableThread(object):
def initStop(self):
self.stop = threading.Event()
self._stopped = False
def stopThread(self):
self._stopped = True
self.stop.set()