I got multiple parallel processes writing into one list in python. My code is:
global_list = []
class MyThread(threading.Thread):
...
def run(self):
results = self.calculate_results()
global_list.extend(results)
def total_results():
for param in params:
t = MyThread(param)
t.start()
while threading.active_count() > 1:
pass
return total_results
I don't like this aproach as it has:
- An overall global variable -> What would be the way to have a local variable for the `total_results function?
- The way I check when the list is returned seems somewhat clumsy, what would be the standard way?