Forget autoexec.py: the right way to automatically starts addons
#19
I've followed the guidance at http://wiki.xbmc.org/index.php?title=HOW...g_services and have an issue using an autologout service started at login.

Before explaining the issue, see the script shown below for reference. addon.xml:

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.autologout"
       name="autologout"
       version="0.2"
       provider-name="Steve Evans">
  <requires>
    <import addon="xbmc.python" version="1.0"/>
  </requires>
  <extension point="xbmc.service"
             library="default.py" start="login">
  </extension>
  <extension point="xbmc.addon.metadata">
    <platform>all</platform>
    <summary lang="en">Auto-logout if left idle</summary>
  </extension>
</addon>

default.py:

Code:
import xbmc,time

# idle time in minutes
IDLE_TIME_MIN = 5
      
s = 1
while s > 0:
    # get idle time
    it = xbmc.getGlobalIdleTime()
    #calculate sleep time in msec
    s = ((IDLE_TIME_MIN * 60) - it ) * 1000
    # sleep for IDLE_TIME_MIN if playing
    if (xbmc.Player().isPlaying()): s = IDLE_TIME_MIN * 60 * 1000
#    print("autologout: Sleeping for %d ms" % s)
    if (s > 0): xbmc.sleep(s)

# log off
print('autologout: Logging off')
xbmc.executebuiltin('System.LogOff')
#print('autologout: Logged off')

I use profiles to manage who gets to watch what, and also have assigned the red button on my remote to logout by tweaking .xbmc/userdata/keymaps/remote.xml by adding the following.

Code:
<red>System.LogOff</red>

Should I forget to hit the red button after viewing something I don't want the kids watching, the above script will log off automatically after 5 minutes on inactivity. Everything appears OK, however, should I remember to log off, this script, launched at logon, isn't terminated. If I log into and out of a few profiles, several copies of the script end up running at the same time, evidenced by the following appearing in the log 5 minutes later:

Code:
19:48:41 T:3069180784  NOTICE: autologout: Logging off
19:48:41 T:3069180784    INFO: Scriptresult: Success
19:48:41 T:3069180784    INFO: Python script interrupted by user
19:48:41 T:3069180784   DEBUG: Thread XBPyThread 3069180784 terminating
19:48:41 T:3010460528  NOTICE: autologout: Logging off
19:48:41 T:3010460528    INFO: Scriptresult: Success
19:48:41 T:3010460528    INFO: Python script stopped
19:48:41 T:3010460528   DEBUG: Thread XBPyThread 3010460528 terminating
19:48:41 T:81242992  NOTICE: autologout: Logging off
19:48:41 T:81242992    INFO: Scriptresult: Success
19:48:41 T:81242992    INFO: Python script stopped
19:48:41 T:81242992   DEBUG: Thread XBPyThread 81242992 terminating
19:48:41 T:3035626352  NOTICE: autologout: Logging off
19:48:41 T:3035626352    INFO: Scriptresult: Success
19:48:41 T:3035626352    INFO: Python script interrupted by user
19:48:41 T:3035626352   DEBUG: Thread XBPyThread 3035626352 terminating

In the above example there were clearly three copies of the script still running.

So, my question is, how should service scripts started at login be terminated?

Steve
Reply


Messages In This Thread
[No subject] - by daledude - 2011-01-31, 23:16
[No subject] - by spiff - 2011-02-01, 12:43
[No subject] - by V-Turn - 2011-02-03, 01:37
[No subject] - by solexalex - 2011-02-05, 21:51
[No subject] - by blinkseb - 2011-02-06, 02:43
[No subject] - by solexalex - 2011-02-06, 13:13
[No subject] - by vikjon0 - 2011-02-13, 19:51
[No subject] - by lophie - 2011-02-24, 21:22
[No subject] - by blinkseb - 2011-02-24, 22:07
[No subject] - by lophie - 2011-02-24, 22:39
[No subject] - by V-Turn - 2011-03-01, 01:13
[No subject] - by Joerg.Liebner - 2011-03-16, 16:51
[No subject] - by spiff - 2011-03-16, 16:56
[No subject] - by cbull - 2011-04-26, 18:45
[No subject] - by malte - 2011-06-02, 11:38
[No subject] - by vikjon0 - 2011-06-04, 13:50
[No subject] - by malte - 2011-06-07, 07:23
How should service scripts started at login be terminated? - by Steve Evans - 2011-09-06, 21:05
[No subject] - by paddycarey - 2011-09-26, 04:45
[No subject] - by Steve Evans - 2011-10-06, 23:29
[No subject] - by _BJ1 - 2011-10-07, 09:41
[No subject] - by queeup - 2011-10-27, 02:42
[No subject] - by LakersFan - 2012-01-28, 00:20
[No subject] - by Martijn - 2012-01-28, 02:28
Logout Mark Read Team Forum Stats Members Help
Forget autoexec.py: the right way to automatically starts addons2