Newbie question: how do I properly end a script?
#16
i think (iirc) that python launches a new interpeter for each instance of a script. eg compare it with launching for example notepad, for each time you start notepad, a new window spawns, instead of activating the old window.
Reply
#17
Unfortunately, the pid file approach failed as well ... I am convinced that the script is not even started a second time, the exception is thrown before the first line of my script is called. I checked with a print statement. In fact, the "-->Python Interpreter Initialized<--" message is not even printed. So there must be something else going on. XBMC does not launch a second instance of my script, or it fails in doing so before it is actually launched.

Any thoughts?
Reply
#18
Not really, do a real Debug Log and pastebin it please
Reply
#19
the problem is that you try to re execute a script with "running" label.
it will make the script fail.

to prevent that, i changed my default.py, now it works like a script launcher.

if the file exist, will ask if you want to end it.
if not, run the script with xbmc.executebuiltin so the 'launcher script" will end end won't have "running label"

here my default.py code:

Code:
# -*- coding: cp1252 -*-

# script constants
__script__       = "Sportlive"
__author__       = "Ppic"
__url__          = "http://code.google.com/p/passion-xbmc/"
__svn_url__      = "http://passion-xbmc.googlecode.com/svn/trunk/scripts/"
__credits__      = "Team XBMC passion, http://passion-xbmc.org/developpement-python/%28script%29-sporlive-display/"
__platform__     = "xbmc media center, [LINUX, OS X, WIN32, XBOX]"
__date__         = "09-01-2010"
__version__      = "1.5"
__svn_revision__  = "$Revision$".replace( "Revision", "" ).strip( "$: " )
__XBMC_Revision__ = "20000" #XBMC Babylon
__useragent__    = "Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1"



import os
import time
import xbmc
import xbmcgui
from traceback import print_exc

BASE_RESOURCE_PATH = os.path.join( os.getcwd(), "resources" )

process = os.path.join( BASE_RESOURCE_PATH , "sportilve.pid")
if os.path.exists(process):
    if xbmcgui.Dialog().yesno("Sportlive est déjà en cours", "Voulez-vous stopper la surveillance?" ):
        os.remove(process)        
else:
    file( process , "w" ).write( "" )
    xbmc.executebuiltin('XBMC.RunScript(%s)' % os.path.join( os.getcwd(), "sportlive.py" ))

in the launched script, i have a loop that seek for the .pid file, if it not there it ends.

this way, i can start the script for changing my filters without stopping the script that run backend (filters are stored in file)
Reply
#20
ppic Wrote:the problem is that you try to re execute a script with "running" label.
it will make the script fail.

to prevent that, i changed my default.py, now it works like a script launcher.

if the file exist, will ask if you want to end it.

Excellent suggestion! Thanks a lot ppic. I just noticed today that your script was suffering from the same error. Great way to solve it!
Reply
#21
yep, will be implemented in next version Wink

that's your topic that make me remember this and make me wrote it, to thanck to you too !
Reply
#22
Alright, I should have seen this coming, but ...

When I exit XBMC without aborting my script first (which works flawlessly now - thanks again ppic for the suggestion), the pid file is not deleted. So when I then restart XBMC and restart the script, it says it is already running and asks me if I want to abort it. Any thoughts on how to get around this, anyone?
Reply
#23
I had the exact same problem when i was doing my Xinbox script back in the day.

I tried looking for a "temp" xbmc folder where I could store my "pid" file.
A folder XBMC wipes when it starts up etc. This would delete your "pid" file and you wouldn't have the script think its running.

I could never find this so I ended up making my script install/modify the autoexec.py script adding a line to delete the "pid" if exsisits.

so, as soon as XBMC is run. Autoexec.py is executed and deletes the "pid" if it is present.

Give that a go.
Reply
#24
BTW: I had the same problem you had and this basically made me give up scripting Xinbox.
the deleting the "pid" file would always cause big memory errors back in the day.

It sounds like this problem has been fixed so I might have to get back into it Tongue
Reply
#25
stanley87 Wrote:so, as soon as XBMC is run. Autoexec.py is executed and deletes the "pid" if it is present.

Give that a go.

Thanks! Sounds like a nice workaround. I never knew of the autoexec.py feature Smile Ideally though, I would prefer a solution that does not require the user to modify a script by hand. After all, since the autoexec.py file is not located in my script's folder but in the main folder instead (and may contain other user-specific modifications), I cannot distribute it with my script.
Reply
#26
Hi Again,

if you search through my posts.
You will find one for a good bit of python code to either create an autoexec.py or modify an exciting one.

It just adds your specific line to the file etc.
So, it does not change what is already there.

EDIT:
HERE IT IS: http://forum.xbmc.org/showthread.php?tid=29378
Reply
#27
Ooh - I like it! I may very well use this approach in the near future. For now though, I will release the first version of my script first. I'm just too anxious to see if anyone is interested in it at all Smile
Reply

Logout Mark Read Team Forum Stats Members Help
Newbie question: how do I properly end a script?0