Newbie question: how do I properly end a script?

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
blittan Offline
Team-XBMC Handyman
Posts: 1,747
Joined: Jun 2004
Reputation: 11
Location: Sweden
Post: #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.

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
If you don't have the time to read them, please don't take the time to post in this forum!
For troubleshooting and bug reporting please make sure you read this first.
find quote
brulsmurf Offline
Member
Posts: 93
Joined: Oct 2008
Reputation: 0
Post: #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?
find quote
blittan Offline
Team-XBMC Handyman
Posts: 1,747
Joined: Jun 2004
Reputation: 11
Location: Sweden
Post: #18
Not really, do a real Debug Log and pastebin it please

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
If you don't have the time to read them, please don't take the time to post in this forum!
For troubleshooting and bug reporting please make sure you read this first.
find quote
ppic Offline
Skilled Python Coder
Posts: 2,711
Joined: Feb 2009
Reputation: 11
Location: France idf
Post: #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)

[Image: widget]
Passion-XBMC Repository Download your SVN skins and addons
TvTunes Addon Download Play your theme while browsing library
TVshow Next Aired display next aired infos from tvrage.com
Logo Downloader Script download Logo/clearart/show thumbs/poster/banner
Bande-Annonce Allociné plugin watch trailers in french and vo
SportLive Script Live score match info in XBMC (not compatible dharma)
(This post was last modified: 2010-01-09 22:22 by ppic.)
find quote
brulsmurf Offline
Member
Posts: 93
Joined: Oct 2008
Reputation: 0
Post: #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!
find quote
ppic Offline
Skilled Python Coder
Posts: 2,711
Joined: Feb 2009
Reputation: 11
Location: France idf
Post: #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 !

[Image: widget]
Passion-XBMC Repository Download your SVN skins and addons
TvTunes Addon Download Play your theme while browsing library
TVshow Next Aired display next aired infos from tvrage.com
Logo Downloader Script download Logo/clearart/show thumbs/poster/banner
Bande-Annonce Allociné plugin watch trailers in french and vo
SportLive Script Live score match info in XBMC (not compatible dharma)
find quote
brulsmurf Offline
Member
Posts: 93
Joined: Oct 2008
Reputation: 0
Post: #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?
find quote
matthuisman Offline
Skilled Python Coder
Posts: 597
Joined: Sep 2006
Reputation: 4
Location: Chch, New Zealand
Post: #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.
find quote
matthuisman Offline
Skilled Python Coder
Posts: 597
Joined: Sep 2006
Reputation: 4
Location: Chch, New Zealand
Post: #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
find quote
brulsmurf Offline
Member
Posts: 93
Joined: Oct 2008
Reputation: 0
Post: #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.
find quote
matthuisman Offline
Skilled Python Coder
Posts: 597
Joined: Sep 2006
Reputation: 4
Location: Chch, New Zealand
Post: #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
(This post was last modified: 2010-01-26 23:33 by matthuisman.)
find quote
brulsmurf Offline
Member
Posts: 93
Joined: Oct 2008
Reputation: 0
Post: #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
find quote
Post Reply