I have recently started playing around with XBMC scripting. Progress is slow, as I have no experience with Python. But it's fun, and the results are not so bad. One thing I have not yet been able to find out though. Here's the thing: when my script starts, a loop is started that shows some info every minute. That loop should end when the user quits the script. Instead, it gives me an error.
Is there any method called by XBMC to end the script? If so, I could do the cleaning up in that method. Is there a script template available anywhere to look at?
brulsmurf
Member Posts: 94 Joined: Oct 2008 Reputation: 0 |
2010-01-05 09:44
Post: #1
|
| find quote |
VictorV
Senior Member Posts: 123 Joined: May 2009 Reputation: 0 Location: Norway |
2010-01-05 13:04
Post: #2
brulsmurf Wrote:I have recently started playing around with XBMC scripting. Progress is slow, as I have no experience with Python. But it's fun, and the results are not so bad. One thing I have not yet been able to find out though. Here's the thing: when my script starts, a loop is started that shows some info every minute. That loop should end when the user quits the script. Instead, it gives me an error. You need to test for a condition in the loop. Code: while not condition: |
| find quote |
brulsmurf
Member Posts: 94 Joined: Oct 2008 Reputation: 0 |
2010-01-05 13:35
Post: #3
VictorV Wrote:You need to test for a condition in the loop. Obviously, but the thing is that I do not know how XBMC tries to end my script. If it calls a method, then I can override/implement that method and make it end my loop. But I need to know the name of the method (or the exact mechanism of how XBMC invokes my script when it tries to stop it) before I can tell the loop to end. Thanks for helping! |
| find quote |
brulsmurf
Member Posts: 94 Joined: Oct 2008 Reputation: 0 |
2010-01-06 21:20
Post: #4
So maybe this "Newbie question" was not as straightforward as I thought ... Meanwhile, I tried the following:
- override/implement the __del__ method in default.py: seems not to be called at all - check if the script is called more than once,but with different parameters: seems not to be the case either. Any ideas, anyone? I really need to do some cleaning up when the script is ended (logout from a website). Besides, the error it returns right now is not the best solution from a user's point of view. Any help welcome! |
| find quote |
blittan
Team-XBMC Handyman Joined: Jun 2004 Reputation: 11 Location: Sweden |
2010-01-06 21:32
Post: #5
not sure how you mean really, but to end a script, use sys.exit()
the user must press some button when ending the script, that you have set up in an action.. there you can do you cleanup before exit. also to not bother the user with errors, encapsulate them in try, except blocks. try: myfunkystuff except: print "we've encountered an error" that way if the myfunkystuff fails we just print an error message to the xbmc.log 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
Member Posts: 94 Joined: Oct 2008 Reputation: 0 |
2010-01-07 11:01
Post: #6
Hey, thanks for the feedback! I realise that I did not properly explain my situation. Here's a better try:
* When the user starts my script, the script starts a loop that shows some info every minute (using the builtin notification system). * The script has no GUI! * So the user stops it by re-selecting it from the Scripts menu * I can see my script trying to stop when I do that, because it says "MyScript (Stopping)" * This takes a number of seconds, and then a popup says "Error in MyScript" or something similar (can't test it from here, sorry). So, to rephrase my question taking Blittan's response into account: * Does the "try ... except" approach allow me to cleanup when the script ends? Or is it thrown at a higher level because XBMC cannot end my script properly? * If the "try ... except" does not work for this case, would it be possible to setup an action that respons to the user selecting the script from the Scripts menu to stop it? I appreciate the help! |
| find quote |
rwparris2
Team-XBMC Python Developer Posts: 1,341 Joined: Jan 2008 Reputation: 2 Location: US |
2010-01-07 13:42
Post: #7
imo this is an xbmc bug.
PHP Code: import timestart it and close it before 5 seconds pass. xbmc returns a script error. btw, sys.exit() annoying closes xbmc, so it isn't really a good way to end scripts. Always read the XBMC online-manual, FAQ and search and search the forum before posting. For troubleshooting and bug reporting please read how to submit a proper bug report. If you're interested in writing addons for xbmc, read docs and how-to for plugins and scripts ||| http://code.google.com/p/xbmc-addons/ |
| find quote |
brulsmurf
Member Posts: 94 Joined: Oct 2008 Reputation: 0 |
2010-01-07 14:19
Post: #8
Great - I've hit an XBMC bug in my first script attempt
![]() My approach is very similar to rwparris2's, except I use the sleep() function: Code: while isRunning:Should I be looking at threading to overcome this problem? I'm not afraid of that, I worked with threads in other programming languages. But if it will not solve my problem, then obviously I would rather not try that approach. |
| find quote |
brulsmurf
Member Posts: 94 Joined: Oct 2008 Reputation: 0 |
2010-01-07 22:10
Post: #9
Quote:* Does the "try ... except" approach allow me to cleanup when the script ends? Or is it thrown at a higher level because XBMC cannot end my script properly?No it doesn't. Tried it, didn't work. Quote:Should I be looking at threading to overcome this problem?No I shouldn't. Tried it, didn't work. Now what? I'm stuck already! |
| find quote |
jmarshall
Team-XBMC Developer Posts: 24,523 Joined: Oct 2003 Reputation: 138 |
2010-01-08 00:06
Post: #10
@rwparris2: Mind doing up a trac ticket with everything we need to reproduce, plus some idea of what *should* happen.
What does running the same thing in python do for instance? There's a patch on trac (or is it in SVN) to improve script exit errors. 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. For troubleshooting and bug reporting please make sure you read this first. ![]() |
| find quote |


![[Image: badge.gif]](http://www.ohloh.net/projects/9132/badge.gif)
Search
Help