Suppose I have a class, And want to read few files from the disk in parallel, and parameterize class parameters. What is the most correct way to do it (and how)?
- Main thread should wait for load_data() action to be over, before anything else is happening.
I thought about threading since it's only I/O actions.
Example of non-parallel implementation (1-Threading):
import pandas as pd
class DataManager(object):
def __init__(self):
self.a = None
self.b = None
self.c = None
self.d = None
self.e = None
self.f = None
def load_data(self):
self.a = pd.read_csv('a.csv')
self.b = pd.read_csv('b.csv')
self.c = pd.read_csv('c.csv')
self.d = pd.read_csv('d.csv')
self.e = pd.read_csv('e.csv')
self.f = pd.read_csv('f.csv')
if __name__ == '__main__':
dm = DataManager()
dm.load_data()
# Main thread is waiting for load_data to finish.
print("finished loading data")