I have a complex class A that calculates data (large matrix calculations) while consuming input from class B.
A itself uses several cores. However, when A needs the next piece of data, it waits a rather long time, since B works in the same main stream.
Since A mainly uses the GPU for computing, I would like B to collect data simultaneously on the CPU.
My last approach:
... and B looks something like this:
class B(object): def __init__(self, ...): ... self._queue = multiprocessing.Queue(10) loader = multiprocessing.Process(target=self._concurrent_loader) def _concurrent_loader(self): while True: if not self._queue.full():
Can this approach be considered a "python" solution?
Since I have little experience with the Python multiprocessing module, I created a simple / simplified approach. However, for me it looks like “hacks."
What would be the best solution for simultaneously loading Class B data from the disk and feeding it through a queue while the main thread does heavy calculations and consumes data from the queue from time to time?
source share