/ src / threads.py.bak
threads.py.bak
 1  """
 2  PyBitmessage does various tasks in separate threads. Most of them inherit
 3  from `.network.StoppableThread`. There are `addressGenerator` for
 4  addresses generation, `objectProcessor` for processing the network objects
 5  passed minimal validation, `singleCleaner` to periodically clean various
 6  internal storages (like inventory and knownnodes) and do forced garbage
 7  collection, `singleWorker` for doing PoW, `sqlThread` for querying sqlite
 8  database.
 9  
10  There are also other threads in the `.network` package.
11  
12  :func:`set_thread_name` is defined here for the threads that don't inherit from
13  :class:`.network.StoppableThread`
14  """
15  
16  import threading
17  
18  from class_addressGenerator import addressGenerator
19  from class_objectProcessor import objectProcessor
20  from class_singleCleaner import singleCleaner
21  from class_singleWorker import singleWorker
22  from class_sqlThread import sqlThread
23  
24  try:
25      import prctl
26  except ImportError:
27      def set_thread_name(name):
28          """Set a name for the thread for python internal use."""
29          threading.current_thread().name = name
30  else:
31      def set_thread_name(name):
32          """Set the thread name for external use (visible from the OS)."""
33          prctl.set_name(name)
34  
35      def _thread_name_hack(self):
36          set_thread_name(self.name)
37          threading.Thread.__bootstrap_original__(self)
38      # pylint: disable=protected-access
39      threading.Thread.__bootstrap_original__ = threading.Thread._Thread__bootstrap
40      threading.Thread._Thread__bootstrap = _thread_name_hack
41  
42  
43  printLock = threading.Lock()
44  
45  __all__ = [
46      "addressGenerator", "objectProcessor", "singleCleaner", "singleWorker",
47      "sqlThread", "printLock"
48  ]