Do you have questions about writing plugins or scripts in Python? Meet the coders here.
-
Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
-
Contact:
Post
by Pako » Sun Mar 01, 2009 9:45 am
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 299 times
-
- __init__.py
- Plugin MMTestWithoutThread
- (4.17 KiB) Downloaded 300 times
-
Bitmonster
- Site Admin
- Posts: 2239
- Joined: Mon Feb 06, 2006 10:28 pm
Post
by Bitmonster » Mon Aug 31, 2009 1:41 pm
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!
-
Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
-
Contact:
Post
by Pako » Mon Aug 31, 2009 8:03 pm
@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