有没有办法使用一个线程的self.app到另一个线程?

时间:2019-02-15 07:41:02

标签: python multithreading python-2.7 pywin32 dispatch

我正在使用self.app在一个线程中打开一个应用程序。我需要通过其他线程或函数来控制self.app。

我可以用一个线程打开,启动,停止,但是当我尝试用另一个线程启动时,它给出了错误。


    def __init__(self, parent):
        self.App = None
        self.App1 = None
        wait_flag=0

    def OnButtonRUNButton(self, event):
        thread.start_new_thread(self.InitializeApplication,())
        if(wait_flag==0):
            sleep(1)
        self.start()

    def InitializeApplication1(self):
        self.App1=Dispatch('X.Application')
        self.App1.Open(self.EnvRbsTesternamePath)
        if self.App1.Measurement.Running == False:
            self.App1.Measurement.Start()
            sleep(1)
        if self.App1.Measurement.Running == True:
            PrintComment ("MEASUREMENT STARTED" , Enable)
        if self.App1.Measurement.Running == True:
            self.App1.Measurement.Stop()
            sleep(1)
        if self.App1.Measurement.Running == False:
            PrintComment ("MEASUREMENT SToped" , Enable)
        wait_flag=1

     def start(self):
         if self.App1.Measurement.Running == False:
             self.App1.Measurement.Start()
             sleep(1)
         if self.App1.Measurement.Running == True:
             PrintComment ("MEASUREMENT STARTED" , Enable)

实际结果:显示错误为:

_getattr__  return self._ApplyTypes_(*args)File "C:\Python27\lib\site-packages\win32com\client\__init__.py", line 456, i
ApplyTypes_  self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),wintypes.com_error: (-2147417842, 'The application called an interface that wmarshalled for a different thread.', None, None)

预期结果: it should run through different thread or function

0 个答案:

没有答案