2011-10-07, 09:41
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.
The pid-file is located at ~/.<USER>/temp/script.program.youraddon/youraddon.PID
Hope this helps
_BJ1
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