I have the following code:
pool = Pool(cpu_count())
pool.imap(process_item, items, chunksize=100)
In the process_item() function I am using structures which are resource demanding to create, but it would be reusable. (but not concurrently shareable) Currently within each call of process_item() it creates the resource in a local variable repeatedly. It would be great performance benefit to create once (for each worker) then reuse
Question
How to have delegated cpu_count() instances for those resource, and how to implement the process_item() function to access the appropriate delegated instance belonging that particular worker?
dill, which can pickle more things in general. Are you okay with using libraries outside the builtins?