Belle II Software development
CalculationQueue Class Reference

Public Member Functions

def __init__ (self)
 
def put (self, name, item, **kwargs)
 
def fill_results (self)
 
def get (self, name)
 
def get_keys (self)
 

Public Attributes

 queue
 The multiprocessing queue to handle.
 
 results
 The results to be filled in the end.
 

Detailed Description

This class is a wrapper around a multiprocessing.Queue

It can be used to send and receive values from the modules while processing the calculation.
You can use it to save - for example - filepaths of outputfiles that you create on the fly.
The added items are all of the type CalculationQueueItem.
The CalculationQueue can be used as a dict. After the termination of the underlaying process
you can access the different entries by their names you gave them when putting them on the queue.

Definition at line 19 of file calculation_queue.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self)
Create a queue.

Definition at line 30 of file calculation_queue.py.

30 def __init__(self):
31 """
32 Create a queue.
33 """
34
35 self.queue = Queue()
36
37 self.results = dict()
38

Member Function Documentation

◆ fill_results()

def fill_results (   self)
Fill the internal dict with the information of the queue.
Do not call this on your own.
Do only call this when the underlying process has ended.

Definition at line 46 of file calculation_queue.py.

46 def fill_results(self):
47 """
48 Fill the internal dict with the information of the queue.
49 Do not call this on your own.
50 Do only call this when the underlying process has ended.
51 """
52 while True:
53 try:
54 result = self.queue.get_nowait()
55 self.results.update({result.name: result.item})
56 except Empty:
57 return
58

◆ get()

def get (   self,
  name 
)
Return the item with the given name or an Exception when it is not found.
Do not call this on your own..

Definition at line 59 of file calculation_queue.py.

59 def get(self, name):
60 """
61 Return the item with the given name or an Exception when it is not found.
62 Do not call this on your own..
63 """
64 self.fill_results()
65 return self.results[name]
66

◆ get_keys()

def get_keys (   self)
Return all possible names of items saved in this queue.
Do not call this on your own.

Definition at line 67 of file calculation_queue.py.

67 def get_keys(self):
68 """
69 Return all possible names of items saved in this queue.
70 Do not call this on your own.
71 """
72 self.fill_results()
73 return list(self.results.keys())
74
75

◆ put()

def put (   self,
  name,
  item,
**  kwargs 
)
Put an item on the queue with the given name. Please keep that adding two items with the same name
overrides one of them!

Definition at line 39 of file calculation_queue.py.

39 def put(self, name, item, **kwargs):
40 """
41 Put an item on the queue with the given name. Please keep that adding two items with the same name
42 overrides one of them!
43 """
44 self.queue.put(CalculationQueueItem(name, item), block=True, **kwargs)
45

Member Data Documentation

◆ queue

queue

The multiprocessing queue to handle.

Definition at line 35 of file calculation_queue.py.

◆ results

results

The results to be filled in the end.

Definition at line 37 of file calculation_queue.py.


The documentation for this class was generated from the following file: