[Django]-I have multiple django tables and want to query the tables in parallel

1👍

This is only a scratch but maybe will help:

import threading
class PararellThread(threading.Thread):
     def __init__(self,model):
         threading.Thread.__init__(self)
         self.model = model
         self.result = []

     def run(self):
         self.result = self.model.objects.all()

def get_objects_in_pararell( models ):
    threads = []
    result = []
    for model in models:
        t = PararellThread(model)
        t.start()
        threads.append(t)

    for thread in threads:
        thread.join()
        for obj in thread.result:
             result.append(obj)

    return result
👤WBAR

Leave a comment