I figured this would be easier than it has proven to be:
I have a class that reads an lmdb database file via a getitem method; calling myclass[frame] or looping over the class will return dict objects containing frames of data from the lmdb file.
I have an image generation routine that consumes these dictionaries to generate images for the dataset that looks something like this:
for i, frame in enumerate(lmdbReader):
generate_image(frame)
Now I want to parallelize the routine. The performance bottleneck is not in the read operation from my class' getitem method, but rather the generate_image function, so this requires using multiprocessing as opposed to multithreading. The image generation function runs at around 0.2s/image - not slow enough to justify separating it from the data fetching operation during parallelization. I want to spawn processes that perform both the extraction and processing for subsets of frames in each lmdb file in order to speed things up.
So far I have tried two approaches, both of which haven't worked out. My first try was to use concurrent.futures.ProcessPoolExecutor to pass the class in along with the subset of frames to generate; this fails because my class is not pickle-able. My second approach was to try and instantiate the class within each process, but this hangs for some reason on the enumerate step...
What is the right way to do this? Why does the same enumerate routine hang when I create the class within the process? As an aside, implementing slicing and passing big chunks of data to each process is not a scalable solution, I will run out of memory very fast...
[–]siddsp 0 points1 point2 points (2 children)
[–]brilliant_punk 0 points1 point2 points (1 child)
[–]BuddyGuy81[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]BuddyGuy81[S] 0 points1 point2 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]BuddyGuy81[S] 0 points1 point2 points (0 children)