I am trying to multiprocess a large number of objects that I need to invoke a class function off. I cant pull the function outside of the class and so just need to figure out a way to speed up the calling of this function.
Many thanks in advance
import time # - Bespoke Class that is standalone - # class sub_class: def __init__(self, item_id, assumptions = "BlahBlahBlah"): self.item_id = item_id self.assumptions = assumptions self.test_count = 0 def some_func(self, adder=1): self.test_count += adder time.sleep(0.1) # - initialise a list of classes - # item_ids = ['A', 'B', 'C', 'D'] items = [sub_class(_id) for _id in item_ids] print( sum(_item.test_count for _item in items) ) # Prints out 0 # - invoke a class level function - # [_item.some_func(adder=2) for _item in items] print( sum(_item.test_count for _item in items) ) # Prints out 8