1
다중 처리 방법에서 SQL Server 2008 R2
에 액세스하고 조작하는 응용 프로그램을 빌드하는 데 pyodbc
을 사용하고 있습니다. 다음과 같이 다중 처리 코드에서 pyodbc 사용
DataEngine
클래스를 설계 : 다음
class DataEngine:
def __init__(self, serverName, databaseName):
self.serverName = serverName
self.databaseName = databaseName
self.cn = pyodbc.connect("driver={SQL Server};server="+ serverName + ";database=" + databaseName + ";trusted_connection=true")
self.cursor = self.cn.cursor()
DataMapper
클래스 :
class DataMapper:
def __init__(self, dataEngine):
self.dataEngine = dataEngine
self.cursor = dataEngine.get_cursor()
그리고 인수와 .exe
파일을 호출하는 함수 정의 :
def func(dataEngine, dataMapper, buildRunId, queueNumber, ServerName, DatabaseName, ExecutableFilePath, DLLFilePath):
os.system(ExecutableFilePath + " " + str(inputRowId) + " " + str(ServerName) + " " + str(DatabaseName) +" " + DLLFilePath)
을
다음 함수는 func
네 별도의 프로세스로 포장되었습니다
queue_0 = Process(target = func, args = (dataEngine, dataMapper, buildRunId, 0, ServerName, DatabaseName))
queue_1 = Process(target = func, args = (dataEngine, dataMapper, buildRunId, 1, ServerName, DatabaseName))
queue_2 = Process(target = func, args = (dataEngine, dataMapper, buildRunId, 2, ServerName, DatabaseName))
queue_3 = Process(target = func, args = (dataEngine, dataMapper, buildRunId, 3, ServerName, DatabaseName))
queue_0.start()
queue_1.start()
queue_2.start()
queue_3.start()
queue_0.join()
queue_1.join()
queue_2.join()
queue_3.join()
위의 코드가 실행되는 경우에는, 나는 오류 메시지가 다음있어 :
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\multiprocessing\forking.py", line 347, in main
self = load(from_parent)
File "C:\Python27\lib\pickle.py", line 1378, in load
return Unpickler(file).load()
File "C:\Python27\lib\pickle.py", line 858, in load
dispatch[key](self)
File "C:\Python27\lib\pickle.py", line 1083, in load_newobj
obj = cls.__new__(cls, *args)
TypeError: object.__new__(pyodbc.Cursor) is not safe, use pyodbc.Cursor.__new__()
Exception AttributeError: "DataEngine instance has no attribute 'cursor'" in <bound method DataEngine.__del__ of <dataengine.DataEngine instance at 0x000000000451FC48>> ignored
내가이 문제를 해결하는 방법을 알 수 있습니까?
감사합니다.