Bug Applescript freezes Video - Put Applescript function in background thread
#1
Exclamation 
VIDEO FREEZES WHEN EXECUTING A SCRIPT.

I've already mentioned this problem AND it's solution in THIS thread.
Developer Tobias has already implemented this code into PLEX and it works flawlessly!

Quote:Tobias Hieta posted on 18 January 2013 - 03:42 PM:

Well the problem is really obvious when looking at the code. The main thread will block until the script has finished. So the solution is to put the function Cocoa_DoAppleScriptFile() in a background thread.

Quote:Tobias Hieta posted on 18 January 2013 - 03:52 PM:

Ok, it was a 10 line change to make it run in the background, I will send you guys a highly untested and experimental version. Don't freak out if it eat your kittens.


I'd like to make a request to the devs to please implement this into XBMC!

Thanks!
Reply
#2
I'd like you to make a request to Tobias for doing a PR with his change against our master branch Smile (not even able to follow that link into plex forums because of missing permissions...)
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#3
(2013-04-10, 12:49)Memphiz Wrote: I'd like you to make a request to Tobias for doing a PR with his change against our master branch Smile

I already did that. But all i got from Tobias was:

Quote:Sent 05 April 2013 - 05:25 PM:
I haven't pushed it upstream. Ask XBMC developers instead.
Reply
#4
Memphiz,
will some dev gonna pick this up or contact Tobias?
Reply
#5
We don't even know what he did because the link doesn't work for us. Is this a forum for PlexPass users or something?
Reply
#6
My bad. The links goes to a PlexPass thread.

But i've already posted all information i got from Tobias:

Quote:Well the problem is really obvious when looking at the code. The main thread will block until the script has finished. So the solution is to put the function Cocoa_DoAppleScriptFile() in a background thread.

It was a 10 line change to make it run in the background.


I've contacted him again and asked for the upstream, but i don't know if he's gonna do it.
Reply
#7
I'm not willing to beg for that code and see no point in reinventing the wheel tbh. I already was in contact with tobias and thought he would be kind enough to work with us/me. If someone gets me that 10 lines of code for xbmc i will take care of applying it into mainline.
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#8
I understand and agree and i don't know why he's so uncooperative.

Would it help to get you the latest PLEX Home Theater version?
Or can this code be found in their github source? - LINK
Reply
#9
(2013-04-12, 11:37)bigbadrabbit Wrote: I understand and agree and i don't know why he's so uncooperative.

Would it help to get you the latest PLEX Home Theater version?
Or can this code be found in their github source? - LINK

Heh

Tobias made experimental build so you can test. Never pushed that code to either XBMC or Plex. Memphis can not run PHT without subscription and even if he could if would be of no use.

Your best bet is to pursue Tobias to push that code to XBMC git.
My skins:

Amber
Quartz

Reply
#10
If he didn't push it to plex - then there might be a reason?
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#11
I suspect so.

Either way plex devs are following this forum, so we best let Tobias speak for himself.
My skins:

Amber
Quartz

Reply
#12
So it's been over a year now since i started this thread and no solution in sight.
Tobias don't care about it and won't respond to any PM regarding this pull request and no one else seems to care about this bug either.

Anybody out there who's willing to help an fix this thing?
Reply
#13
Mhhh i didn't find a way to background the script execution tbh. Also apple tells us that applescripts HAVE to run from the main thread. I moved it into a background thread via "performSelectorInBackground" and can confirm that it indead spawns a new thread and tries to start the apple script from there. While the script runs it still blocks the rest of XBMC (because it blocks the apple event queue of our process).

I tried a simple test script like

Code:
display dialog "Hello World"

Which blocks until i confirm the dialog. Well until anybody tells me a working solution i consider this so damnit low prio thing. (i already wasted alot of time for this stupid feature anyway now).
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply
#14
(2014-05-18, 18:44)Memphiz Wrote: Mhhh i didn't find a way to background the script execution tbh. Also apple tells us that applescripts HAVE to run from the main thread. I moved it into a background thread via "performSelectorInBackground" and can confirm that it indead spawns a new thread and tries to start the apple script from there. While the script runs it still blocks the rest of XBMC (because it blocks the apple event queue of our process).

I tried a simple test script like

Code:
display dialog "Hello World"

Which blocks until i confirm the dialog. Well until anybody tells me a working solution i consider this so damnit low prio thing. (i already wasted alot of time for this stupid feature anyway now).

I just tried a test where I wrote a small python script which ran a applescript in the background while a movie was playing. Taking your example of Display Dialog "Hello World" a window came up waiting for input but the movie continued playing and I was still able to use the Apple Remote to pause the movie, exit the movie, go in and out of menus and even exit XBMC all while the "Hello World" window was displayed waiting for me to press a button to clear the window.

I used a a python script to run the apple script in the background like the following:
Code:
import sys
import os

whichOS = sys.platform

if whichOS == 'darwin':
    whichScript = "\"" + os.path.splitext(__file__)[0] + ".applescript\""

    os.system("/usr/bin/osascript " + whichScript + " &")

Putting the "&" at the end runs the applescript in the background. I executed the python script from keyboard.xml with the RunScript command. Using this approach requires no changes to XBMC itself. By the way, I tried this in XBMC 12.3, I have not tried this in Gotham.

Hope this helps.

EDIT: I applied this method to the applescript I use to increase and decrease the OS X system volume and now I no longer get a small pause whenever I press the "+" or "-" on the apple remote. Thank you for giving me this solution as I was looking for a way to get rid of the small pause.
Kodi 17, Transparency Skin
PogoPlug v4 running Arm Linux 4.4.63 as MySQL (mariadb) server.
Mac OS 10.12.5
2015 27" iMac 3.3 GHz Quad, 16GB RAM, 1TB SSD
2015 13" Macbook Pro, 8GB RAM, 256GB SSD
AppleTV 4 TV OS 10
Reply
#15
Yeah this works because it spawns a new process (/usr/bin/osascript) - not only a new thread. New process means - it has its own event queue and so it doesn't block the XBMC event queue. But spawning a process is nothing we want to implement in the core for XBMC. If it doesn't work with doing it in an own thread than its a pity and thats it.

But thx for the workaround by sideloading the script via python.
AppleTV4/iPhone/iPod/iPad: HowTo find debug logs and everything else which the devs like so much: click here
HowTo setup NFS for Kodi: NFS (wiki)
HowTo configure avahi (zeroconf): Avahi_Zeroconf (wiki)
READ THE IOS FAQ!: iOS FAQ (wiki)
Reply

Logout Mark Read Team Forum Stats Members Help
Applescript freezes Video - Put Applescript function in background thread0