在下面发布的代码中,我正在对Process进行子类化。正如一些教程中所述,必须调用.start才能启动工作流程。
我面临的问题是,我无法调用.start()方法,因为它会导致应用程序崩溃并生成下面发布的错误消息。相反,我调用.run()方法。
请告诉我为什么我不能使用.start(),它是如何生成错误消息的,以及如何修复它,这样我就可以使用/start()
笔记
:下面发布的代码位于Web服务中
错误消息
:
File "C:\Python310\lib\multiprocessing\process.py", line 100, in _check_closed
if self._closed:
AttributeError: 'KeyGridCellsProcessing' object has no attribute '_closed'
密码
:
class KeyGridCellsProcessing(Process):
@staticmethod
def newInstance(pNameSuffix,row,col,_pixelsValuesSatisfyThresholdInWindowedSegment,pixelsValuesSatisfyThresholdInTIFFImageDatasetCnt):
keyGridCellsProcessing = KeyGridCellsProcessing(pNameSuffix,row,col,_pixelsValuesSatisfyThresholdInWindowedSegment,pixelsValuesSatisfyThresholdInTIFFImageDatasetCnt)
KeyGridCellsProcessing.processesCollector.append(KeyGridCellsProcessing)
return keyGridCellsProcessing
@staticmethod
def setDatasetElevationsTIFFInEPSG25832(datasetElevationsTIFFInEPSG25832):
KeyGridCellsProcessing.datasetElevationsTIFFInEPSG25832 = datasetElevationsTIFFInEPSG25832
@staticmethod
def setNDVIsTIFFWindowedSegmentContentsInEPSG25832(NDVIsTIFFWindowedSegmentContentsInEPSG25832):
KeyGridCellsProcessing.NDVIsTIFFWindowedSegmentContentsInEPSG25832 = NDVIsTIFFWindowedSegmentContentsInEPSG25832
@staticmethod
def setMainTIFFImageDatasetContents(mainTIFFImageDatasetContents):
KeyGridCellsProcessing.mainTIFFImageDatasetContents = mainTIFFImageDatasetContents
@staticmethod
def waitForProcessToFinish():
for p in KeyGridCellsProcessing.processesCollector:
p.join()
# logger.debug(f"process:{p}")
# exit()
def __init__(self,pNameSuffix,row,col,_pixelsValuesSatisfyThresholdInWindowedSegment,pixelsValuesSatisfyThresholdInTIFFImageDatasetCnt):
# self.queue = queue
self.pNameSuffix = pNameSuffix
self.row = row
self.col = col
self._pixelsValuesSatisfyThresholdInWindowedSegment = _pixelsValuesSatisfyThresholdInWindowedSegment
self.pixelsValuesSatisfyThresholdInTIFFImageDatasetCnt = pixelsValuesSatisfyThresholdInTIFFImageDatasetCnt
self.fourCornersOfKeyWindowInEPSG4326 = []
def run(self):
runStartTime = time.time()
#logic
...
...
runEndTime = time.time() - runStartTime
KeyGridCellsProcessing.runMethodForKeyGridCellsExecutionTimeAccumulator+=runEndTime
@staticmethod
def enqueue():
KeyGridCellsProcessing.keyGridCellsQueue.put([KeyGridCellsProcessing.NDVIsPer10mX10mForKeyWindow,
......,
......,
......,
......,
......,
], block=True, timeout=None)
@staticmethod
def dequeue():
deqeueStartTime = time.time()
item = KeyGridCellsProcessing.keyGridCellsQueue.get(block=True, timeout=None)
KeyGridCellsProcessing.executionTimeOfDequeueProcess = time.time() - deqeueStartTime
return item
@staticmethod
def shutdownQueue():
KeyGridCellsProcessing.keyGridCellsQueue.close()
KeyGridCellsProcessing.keyGridCellsQueue.join_thread()
def startProcessing(self):
#self.start()#<=========== causes the app to crash
self.run() #works