Kill python script gracefully : "Py_EndInterpreter: not the last thread"

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
bigfatpaulyj Offline
Junior Member
Posts: 3
Joined: Nov 2011
Reputation: 0
Question  Kill python script gracefully : "Py_EndInterpreter: not the last thread"
Post: #1
Hi folks, I'm trying to write a python script addon for xbmc. The script shall make use of multiple threads, some listening on sockets, some waiting for callbacks to xbmc.Player.onPlayBackEnded() etc etc...

Now my question relates to how to "gracefully" let XBMC kill a python script. Currently my script is run from within the Programs section of the main menu. It starts when you click the script once... and it will try to stop it when you click it again. Now the problem is, how can my script detect that XBMC wants it to die, and then cleanup and die gracefully. Sockets have to be closed, threads have to end, resources have to be released. I cannot see how this should happen in the context of XBMC. My current problem is that i get the following error...

18:48:06 T:3045889920 M:1261899776 INFO: Stopping script with id: 2
18:48:08 T:2832939888 M:1262559232 INFO: Scriptresult: Interrupted by user
18:48:08 T:2832939888 M:1262559232 INFO: msg: Fatal Python error: Py_EndInterpreter: not the last thread

This is because XBMC kills the main thread, but a child thread still existed.

I have searched for a solution to this all over the place but cannot locate the answer.

Any help greatly appreciated.
find quote
Martijn Offline
Team-XBMC
Posts: 10,241
Joined: Jul 2011
Reputation: 153
Location: Dawn of time
Post: #2
Something like this should do it and then probably in each thread started.

PHP Code:
if xbmc.abortRequested:
            
log('XBMC abort requested, aborting')
            break 

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
find quote
bigfatpaulyj Offline
Junior Member
Posts: 3
Joined: Nov 2011
Reputation: 0
Post: #3
Thanks, ok ya this seems to have fixed the problem. Big Grin
find quote
Martijn Offline
Team-XBMC
Posts: 10,241
Joined: Jul 2011
Reputation: 153
Location: Dawn of time
Post: #4
bigfatpaulyj Wrote:Thanks, ok ya this seems to have fixed the problem. Big Grin

Your welcome Wink

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
find quote