Page 1 of 1

WorkerThread

Posted: Sun Mar 01, 2009 9:45 am
by Pako
I would like to revise MediaMonkey plugin so that communication with the COM object was in a separate thread (as a plugin DVBviewer). I spent this many hours, but I do not have success. I did two test plugins. Are attached. Plugin "MMTestWithoutThread" works as expected, while the plugin "MMTestWithThread" does not work. There is this error:

Code: Select all

      Error in Action: "MMTestWithThread: Play"
      Traceback (most recent call last) (851):
        File "D:\Programs\E\EventGhost\eg\Classes\ActionBase.py", line 166, in CallWrapper
        File "D:\Programs\E\EventGhost\plugins\MMTestWithThread\__init__.py", line 126, in __call__
        File "D:\Programs\E\EventGhost\plugins\MMTestWithThread\__init__.py", line 108, in SendCommandThroughCOM
        File "win32com\client\dynamic.pyc", line 500, in __getattr__
      AttributeError: SongsDB.SDBApplication.Player
I need help.
Thanks, Pako

Re: WorkerThread

Posted: Mon Aug 31, 2009 1:41 pm
by Bitmonster

Code: Select all

            self.workerThread.CallWait(
                self.workerThread.MM.Player.Play()
            )
This won't work. You call Play() in the actionThread and then push the result of Play() to your worker thread. So even if it wouldn't crash before, it would crash after this, because the result of Play() isn't a callable.

Also you have to make sure, that your COM object access is only initiated from the thread that created the COM object. So you have to implement something like this in your worker thread:

Code: Select all

def DoCommand(self, command):
    getattr(self.MM.Player, command)()
and actions like:

Code: Select all

from functools import partial

class Play(eg.ActionClass):
    name = "Play"
    description = "Play."

    def __call__(self):
        print "Command Play"
        self.plugin.workerThread.CallWait(partial(self.plugin.workerThread.DoCommand, 'Play'))


Re: WorkerThread

Posted: Mon Aug 31, 2009 8:03 pm
by Pako
@Bitmonster
Thank you very much for substantial assistance.
When he knows how to do it, it's simple :) .
Now it works nicely and I soon found out, how to set or get some value (eg volume).
However, for the complete revision of the plugin I'll need some time.

Pako