2019-10-31 13:13:36 +01:00
|
|
|
"""Most of the queues used by bitmessage threads are defined here."""
|
2019-12-30 13:10:02 +01:00
|
|
|
import queue as Queue
|
2019-10-31 13:13:36 +01:00
|
|
|
|
|
|
|
import threading
|
2020-09-11 17:17:10 +02:00
|
|
|
import time
|
|
|
|
import traceback
|
2017-06-27 13:25:12 +02:00
|
|
|
|
2020-06-15 12:24:11 +02:00
|
|
|
try:
|
|
|
|
from multiqueue import MultiQueue
|
|
|
|
except ModuleNotFoundError:
|
2020-08-07 19:28:57 +02:00
|
|
|
from pybitmessage.multiqueue import MultiQueue
|
2019-10-31 13:13:36 +01:00
|
|
|
|
|
|
|
class ObjectProcessorQueue(Queue.Queue):
|
|
|
|
"""Special queue class using lock for `.threads.objectProcessor`"""
|
|
|
|
|
|
|
|
maxSize = 32000000
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
Queue.Queue.__init__(self)
|
|
|
|
self.sizeLock = threading.Lock()
|
|
|
|
#: in Bytes. We maintain this to prevent nodes from flooding us
|
|
|
|
#: with objects which take up too much memory. If this gets
|
|
|
|
#: too big we'll sleep before asking for further objects.
|
|
|
|
self.curSize = 0
|
|
|
|
|
|
|
|
def put(self, item, block=True, timeout=None):
|
2020-01-21 13:13:09 +01:00
|
|
|
"""Putting values in queues"""
|
2019-10-31 13:13:36 +01:00
|
|
|
while self.curSize >= self.maxSize:
|
|
|
|
time.sleep(1)
|
|
|
|
with self.sizeLock:
|
|
|
|
self.curSize += len(item[1])
|
|
|
|
Queue.Queue.put(self, item, block, timeout)
|
|
|
|
|
|
|
|
def get(self, block=True, timeout=None):
|
2020-01-21 13:13:09 +01:00
|
|
|
"""Getting values from queues"""
|
2019-10-31 13:13:36 +01:00
|
|
|
item = Queue.Queue.get(self, block, timeout)
|
|
|
|
with self.sizeLock:
|
|
|
|
self.curSize -= len(item[1])
|
|
|
|
return item
|
|
|
|
|
2020-09-11 17:17:10 +02:00
|
|
|
class addressGeneratorQueueClass(Queue.Queue):
|
|
|
|
|
|
|
|
debug_file = open("/tmp/addressgenerator.log", "a")
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
Queue.Queue.__init__(self)
|
|
|
|
|
2020-09-14 16:33:07 +02:00
|
|
|
def put(self, item, block =True, timeout=None):
|
|
|
|
self.debug_file.write('---this put condition--\n')
|
|
|
|
self.debug_file.write('this put condition- ')
|
|
|
|
self.debug_file.write('Current-thread-{} \n'.format(
|
|
|
|
threading.current_thread().name))
|
|
|
|
self.debug_file.write('Traceback-{} \n'.format(
|
2020-09-15 16:50:56 +02:00
|
|
|
str(traceback.format_stack())))
|
2020-09-14 16:33:07 +02:00
|
|
|
self.debug_file.write('Printig the put item-{}'.format(
|
|
|
|
item))
|
|
|
|
Queue.Queue.put(self, item, block, timeout)
|
|
|
|
self.debug_file.write('-------------------\n \n')
|
|
|
|
|
|
|
|
|
|
|
|
def get(self, block =True, timeout=None):
|
|
|
|
self.debug_file.write('---this get condition ---\n')
|
|
|
|
self.debug_file.write('Current-thread-{} \n '.format(
|
|
|
|
threading.current_thread().name))
|
|
|
|
self.debug_file.write('Traceback-{} \n'.format(
|
2020-09-15 16:50:56 +02:00
|
|
|
str(traceback.format_stack())))
|
2020-09-14 16:33:07 +02:00
|
|
|
item = Queue.Queue.get(self, block, timeout)
|
|
|
|
self.debug_file.write('Printig the get item-{}'.format(
|
|
|
|
str(item)))
|
|
|
|
self.debug_file.write('-------------------\n \n')
|
|
|
|
return item
|
|
|
|
|
|
|
|
|
|
|
|
class apiAddressGeneratorReturnQueueQueueClass(Queue.Queue):
|
|
|
|
|
|
|
|
debug_file = open("/tmp/apiAddressGeneratorReturnQueue.log", "a")
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.debug_file.write(
|
|
|
|
'apiAddressGeneratorReturnQueueQueue started.....\n'
|
|
|
|
)
|
|
|
|
Queue.Queue.__init__(self)
|
|
|
|
|
2020-09-11 17:17:10 +02:00
|
|
|
def put(self, item, block =True, timeout=None):
|
|
|
|
self.debug_file.write('-------------------\n')
|
|
|
|
self.debug_file.write('this put condition- ')
|
2020-09-14 16:33:07 +02:00
|
|
|
self.debug_file.write('@@@@@@ put 51 @@@@@@\n')
|
2020-09-11 17:17:10 +02:00
|
|
|
self.debug_file.write(threading.current_thread().name)
|
2020-09-14 16:33:07 +02:00
|
|
|
self.debug_file.write('@@@@@@ put 53 @@@@@@\n')
|
|
|
|
self.debug_file.write(str(traceback.print_exc()))
|
|
|
|
self.debug_file.write('@@@@@@ put 55 @@@@@@\n')
|
2020-09-11 17:17:10 +02:00
|
|
|
Queue.Queue.put(self, item, block, timeout)
|
2020-09-14 16:33:07 +02:00
|
|
|
self.debug_file.write('@@@@@@ put 57 @@@@@@\n')
|
2020-09-11 17:17:10 +02:00
|
|
|
self.debug_file.write('-------------------\n')
|
|
|
|
|
|
|
|
|
2020-09-14 16:33:07 +02:00
|
|
|
def get(self, block =True, timeout=None):
|
2020-09-11 17:17:10 +02:00
|
|
|
self.debug_file.write('-------------------\n')
|
|
|
|
self.debug_file.write('this get condition -')
|
2020-09-14 16:33:07 +02:00
|
|
|
self.debug_file.write('@@@@@@ get 64 @@@@@@')
|
2020-09-11 17:17:10 +02:00
|
|
|
self.debug_file.write(threading.current_thread().name)
|
2020-09-14 16:33:07 +02:00
|
|
|
self.debug_file.write('@@@@@@ get 66 @@@@@@')
|
|
|
|
self.debug_file.write(str(traceback.print_exc()))
|
|
|
|
self.debug_file.write('@@@@@@ get 68 @@@@@@')
|
2020-09-11 17:17:10 +02:00
|
|
|
item = Queue.Queue.get(self, block, timeout)
|
2020-09-14 16:33:07 +02:00
|
|
|
self.debug_file.write('@@@@@@ get 70 @@@@@@')
|
2020-09-11 17:17:10 +02:00
|
|
|
self.debug_file.write('-------------------\n')
|
|
|
|
return item
|
2019-10-31 13:13:36 +01:00
|
|
|
|
2020-09-14 16:33:07 +02:00
|
|
|
|
|
|
|
|
2017-02-08 13:41:56 +01:00
|
|
|
workerQueue = Queue.Queue()
|
|
|
|
UISignalQueue = Queue.Queue()
|
2020-09-11 17:17:10 +02:00
|
|
|
addressGeneratorQueue = addressGeneratorQueueClass()
|
2019-11-06 10:38:42 +01:00
|
|
|
#: `.network.ReceiveQueueThread` instances dump objects they hear
|
|
|
|
#: on the network into this queue to be processed.
|
2017-02-08 13:41:56 +01:00
|
|
|
objectProcessorQueue = ObjectProcessorQueue()
|
2017-06-27 13:25:12 +02:00
|
|
|
invQueue = MultiQueue()
|
|
|
|
addrQueue = MultiQueue()
|
2017-05-25 14:59:18 +02:00
|
|
|
portCheckerQueue = Queue.Queue()
|
2017-07-06 19:45:36 +02:00
|
|
|
receiveDataQueue = Queue.Queue()
|
2019-10-31 13:13:36 +01:00
|
|
|
#: The address generator thread uses this queue to get information back
|
|
|
|
#: to the API thread.
|
2020-09-14 16:33:07 +02:00
|
|
|
apiAddressGeneratorReturnQueue = apiAddressGeneratorReturnQueueQueueClass()
|
2019-10-31 13:13:36 +01:00
|
|
|
#: for exceptions
|
2018-10-03 17:42:12 +02:00
|
|
|
excQueue = Queue.Queue()
|
2020-09-11 17:17:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
#new
|