Ejemplo n.º 1
0
 def multiThreadReleaseThreadData(self):
     '''
     多线程的单个线程操作完成时释放Marshalled Interface,注意使用锁操作机制保证取得的对象唯一性
     :return:
     '''
     self._myStream.Seek(0, 0)
     pythoncom.CoReleaseMarshalData(self._myStream)
Ejemplo n.º 2
0
	def close(self):
		''' Close a Modelica/SimulationX model
		'''
		sim = None
		try:
			doc = win32com.client.Dispatch(pythoncom.CoUnmarshalInterface(self._marshalled_doc, pythoncom.IID_IDispatch))
			self._marshalled_doc.Seek(0, pythoncom.STREAM_SEEK_SET)
			if not type(doc) is types.NoneType:
				sim = doc.Application
				sim.Interactive = False
				doc.Close(False)
				doc = None
				pythoncom.CoReleaseMarshalData(self._marshalled_doc)
				self._marshalled_doc = None
		except win32com.client.pywintypes.com_error:
			print 'SimulationX: COM error.'
		except:
			print 'SimulationX: Error.'
		finally:
			SimulatorBase.Model.close(self)
			if not type(sim) is types.NoneType:
				sim.Interactive = True
				sim = None

		if hasattr(self, 'variableTree'):
			del self.variableTree
		if hasattr(self, '_availableIntegrationAlgorithms'):
			del self._availableIntegrationAlgorithms
		if hasattr(self, '_solverByName'):
			del self._solverByName
		if hasattr(self, '_IntegrationAlgorithmHasFixedStepSize'):
			del self._IntegrationAlgorithmHasFixedStepSize
		if hasattr(self, '_IntegrationAlgorithmCanProvideStepSizeResults'):
			del self._IntegrationAlgorithmCanProvideStepSizeResults
Ejemplo n.º 3
0
    def check_password(self, path, name, password):
        pythoncom.CoInitialize()
        
        xl = win32com.client.DispatchEx('Excel.Application')
        xls_stream = pythoncom.CreateStreamOnHGlobal()   
         
        pythoncom.CoMarshalInterface(xls_stream, 
                                    pythoncom.IID_IDispatch, 
                                    xl._oleobj_, 
                                    pythoncom.MSHCTX_LOCAL, 
                                    pythoncom.MSHLFLAGS_TABLESTRONG) 

        xls_stream.Seek(0,0)
        
        myUnmarshaledInterface = pythoncom.CoUnmarshalInterface(xls_stream, pythoncom.IID_IDispatch)    
        xl = win32com.client.Dispatch(myUnmarshaledInterface)

        try:
            xl_wb = xl.Workbooks.Open('%s\\%s' %(path,name), False, True, None, password)
            if xl_wb.Name:
                xl_wb.Close(False)

                xls_stream.Seek(0,0)
                pythoncom.CoReleaseMarshalData(xls_stream)
                xls_stream = None
                pythoncom.CoUninitialize()

                return password
        except:
            xls_stream.Seek(0,0)
            pythoncom.CoReleaseMarshalData(xls_stream)
            xls_stream = None
            pythoncom.CoUninitialize()
            return None

        xls_stream.Seek(0,0)
        pythoncom.CoReleaseMarshalData(xls_stream)
        xls_stream = None
        pythoncom.CoUninitialize()
        return None
    def __del__(self):
        try:
            super(MarshalledCallbackInfo,self).__del__()

            logging.info("MarshalledCallbackInfo.__del__       : releasing Marshalled interface pointer" )

            # Clear the stream now that we have finished
            self.myStream.Seek(0,0)
            pythoncom.CoReleaseMarshalData(self.myStream)
            self.myStream = None
            delattr(self,'myStream')
        except Exception as ex:
            logging.info("MarshalledCallbackInfo.__del__   error : " + 
                 LocalsEnhancedErrorMessager.Enhance(ex,str(locals())))
            raise