Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

WorkerThread

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
Post Reply
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

WorkerThread

Post 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
Attachments
__init__.py
Plugin MMTestWithThread
(5.2 KiB) Downloaded 280 times
__init__.py
Plugin MMTestWithoutThread
(4.17 KiB) Downloaded 283 times
User avatar
Bitmonster
Site Admin
Posts: 2239
Joined: Mon Feb 06, 2006 10:28 pm

Re: WorkerThread

Post 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'))

Please post software-related questions in the forum - PMs will only be answered, if really private, thanks!
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: WorkerThread

Post 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
Post Reply