Forget autoexec.py: the right way to automatically starts addons
#22
I have solved this with a pid-file. if a pid-file isn't present, the process runs at first time, otherwise your process is already running. Don't forget to delete the pid-file if your process terminate correctly otherwise a new process will not start.

Code:
import os
import subprocess
import xbmc
import xbmcaddon
import xbmcgui

__addonname__ = 'script.program.youraddon'
__datapath__ = xbmc.translatePath(os.path.join('special://temp',__addonname__))
if not os.path.exists(__datapath__): os.makedirs(__datapath__)

PIDFILE = os.path.join(__datapath__, 'youraddon.PID')

def isPIDFile():
    # check for PIDFILE, if no PIDFILE available, user or system has
    # powered|logged on the system at first time else a process is already
    # running
    
    pf = False
        syscmd = subprocess.Popen(['pidof','xbmc.bin'],stdout=subprocess.PIPE)
        pidofXBMC =  syscmd.stdout.read().strip()
    if not os.path.isfile(PIDFILE):
            f = open(PIDFILE, 'w')
            f.write(pidofXBMC + '\n')
        f.close()
        print 'system powered on first time'
    else:
        f = open(PIDFILE, 'r')
        pidofFile = f.readline().strip()
        f.close()
        if pidofFile == pidofXBMC:
            pf = True
        else:
                # XBMC is probably crashed before
                f = open(PIDFILE, 'w')
                f.write(pidofXBMC + '\n')
                f.close()
                print 'found old PIDFile, XBMC probably crashed'
    return pf


### MAIN SERVICE ###

if not isPIDFile():
    # your application code
    # last line:
    if os.path.isfile(PIDFILE): os.remove(PIDFILE)
else:
    # do nothing
    pass


The pid-file is located at ~/.<USER>/temp/script.program.youraddon/youraddon.PID
Hope this helps

_BJ1
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
[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