Python Class Instance in MultiProcess giving error when it contains DB connection

30 views Asked by At
import oracledb
import getpass
import pyodbc
import multiprocessing

from datetime import datetime


def insertInOracle_worker(test):
    print(type(test))
    

if __name__ == "__main__":

    username="XXXXX"
    userpwd = 'XXXXX'
    host = "xxxxx.corporate.co"
    port = 1521
    service_name = "servicexxxx"
    dsn = f'{username}/{userpwd}@{host}:{port}/{service_name}'
    o_connection=oracledb.connect(dsn)
    #o_connection="Hello connection"
    list_of_columns= [['MEMBER_TYPE', 'CHAR',1]]
    oracle_import = Oracle_import(o_connection,"DISCOUNT_PROFILE",list_of_columns)      
    test = "ADRIAN"
    p1 = multiprocessing.Process(target=insertInOracle_worker,args=[oracle_import])     
    p1.start()

In the above code I get an error when I am connected to Oracle by o_connection and pass the class instance as a parameter for multiprocessing. If I comment it and remove the comment for o_connection="Hello connection", then its all fine. Seems like pickling the connection is a problem. I am quite new to python and looking for suggestions.

I need to pass the my class for further purposes of background process.

0

There are 0 answers