Thread Rating:
  • 0 Vote(s) - 0 Average
Kill python script gracefully : "Py_EndInterpreter: not the last thread"
#1
Question 
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.
Reply
#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 
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#3
Thanks, ok ya this seems to have fixed the problem. Big Grin
Reply
#4
bigfatpaulyj Wrote:Thanks, ok ya this seems to have fixed the problem. Big Grin

Your welcome Wink
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply



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