'Share a COM object across multi processes in python

I have use case where I have to do some operations on an excel file in python.
There will be 2 processes running in parallel.
The main.py file will open an excel sheet and starts the 3 processes.

  1. First process - does some calculation on the data from excel.
  2. Second process - Continuously writes data in the excel at fixed frequency like every 1 min.

Now my requirement is when I start the processes I need to share the excel object between the processes.

I have referred to few examples online and written the below code:

from multiprocessing import Process


def fun(name):
    print(f'hello {name}')

def main():
    excelObj =  OpenExcelApp()  # def which opens the excel application and returns the excel object 

    input_process = Process(target=self.input_data, args=[excelObj])  #input_data def fetches data from db and writes it into the excel file

    triggerCalc_process = Process(target= self.trigger_calc, args=[excelObj]) #triggers for calculation

    input_process.start()
    triggerCalc_process.start()

if __name__ == '__main__':
    main()

Can anyone suggest me what am I missing or doing wrong here. Many thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source