Kodi Community Forum
fixing xbmc.abortRequested - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
+--- Thread: fixing xbmc.abortRequested (/showthread.php?tid=354577)



fixing xbmc.abortRequested - scott967 - 2020-05-19

So I am attempting to keep some orphaned scripts running in Kodi 19.  I tried naively just replacing some statements like
Code:
if not xbmc.abortRequested:
with
Code:
if not xbmc.Monitor().abortRequested():
and while that runs, on a couple of scripts when user initiates shutdown I get logged
Code:
trigger Monitor abort request
and
Code:
script didn't stop in 5 seconds - let's kill it

These scripts seemed to exit OK before, so I wonder what I am doing wrong?

scott s.
.


fixing xbmc.abortRequested - enen92 - 2020-05-20

Can you point to the actual code?


RE: fixing xbmc.abortRequested - pkscout - 2020-05-20

One thing to look for is if there are any instances of xbmc.sleep(x).  That is a blocker, and the script won't exit until the sleep timer expires.  That can be replaced with xbmc.Monitor().waitForAbort(y).  There are two big differences.  First, waitForAbort will terminate as soon as an abort is requested.  Second, the parameter for waitForAbort is SECONDS, where as xbmc.sleep is in MILLISECONDS.  One other quick thing.  I got dinged during code review when submitting something to the addon repo for calling xbmc.Monitor() over and over again.  The suggestion was to instantiate a global instance using something like:

python:

KODIMONITOR = xbmc.Monitor()
KODIMONITOR.waitForAbort( 5 )



RE: fixing xbmc.abortRequested - scott967 - 2020-05-20

(2020-05-20, 07:15)pkscout Wrote: _daemonOne thing to look for is if there are any instances of xbmc.sleep(x).  That is a blocker, and the script won't exit until the sleep timer expires.  That can be replaced with xbmc.Monitor().waitForAbort(y).  There are two big differences.  First, waitForAbort will terminate as soon as an abort is requested.  Second, the parameter for waitForAbort is SECONDS, where as xbmc.sleep is in MILLISECONDS.  One other quick thing.  I got dinged during code review when submitting something to the addon repo for calling xbmc.Monitor() over and over again.  The suggestion was to instantiate a global instance using something like:

python:

KODIMONITOR = xbmc.Monitor()
KODIMONITOR.waitForAbort( 5 )
Thanks.  One of the problem scripts is service.skin.widgets which I have forked and created a matrix / python 3 branch on my fork here:  python3 branch

This is without a commit to make the change to xbmc.abortRequested
It starts as a Kodi service and just creates an instance of Main class At the end of its __init__ it calls a _daemon method that runs in a while - else loop:  daemon waiting for Kodi to abort. It does do an xbmc.sleep(500) in the while loop.

scott s.
.


RE: fixing xbmc.abortRequested - scott967 - 2020-05-26

I think I have the first one sorted.  I did need to add the waitForAbort method.  The structure of the module gives me fits as I am not comfortable with the scoping rules in Python and that caused me some grief.  The module is essentially a big class with an instance created when it is run.  The class does a bunch of things in its __init__ then calls its _daemon method until Kodi terminates it.   It looked like the best way to adapt the existing structure was to create an xbmc.Monitor() instance during the __init__ and use that.  But I was having trouble using that monitor instance due to it being out of scope.  I got it working finally via trial/error by using self.mymonitorinstance.method() but I don't really understand why that works and not just mymonitorinstance.method().

I'm also not sure how best to get the abort.  I take it the concept is to spend most time in the waitForAbort sleep and when the module "wakes up" do what needs to be done without looking for an abort, then go back to sleep.

scott s.
.