Multithreading python and XBMC is trouble?
#1
Question 
Hi, I'm coding a multi threading process and if I quit XBMC before all threads are finished, I get a C++ execution error, and the log refers to:

msg: Fatal Python error: Py_EndInterpreter: not the last thread

So I had tried to use "signal" to catch the interruption and launch a cleanup function, but it didn't worked because the addon itself isn't the main thread.

Anyone have any experience handling this?
Reply
#2
Make sure all the threads you have spawned in your python code have terminated before you allow your python script to exit. See util.py and home.py in mythbox for more details.
MythBox for XBMC - http://mythbox.googlecode.com
Reply
#3
analogue Wrote:Make sure all the threads you have spawned in your python code have terminated before you allow your python script to exit. See util.py and home.py in mythbox for more details.

I'm not using xbmcgui to create the object, so how can I bind a cleanup function without it?
Reply
#4
Track all the threads you create and at the end of your script just thread.join() on them all. Although xbmc should probably not segfault when an error like this occurs!
Reply
#5
i've got this problem with tvtunes too if i quit xbmc when i'm in library.
Reply
#6
Mnuu Wrote:Track all the threads you create and at the end of your script just thread.join() on them all. Although xbmc should probably not segfault when an error like this occurs!

You see, all threads I created are stored in one sequence, so it's easy to join() or exit() all of them, but how can I assure the interpreter launch a cleanup function when the script gets interrupted?

The signal function should handle this, but the script is launched by XBMC as a child, not as main.
Reply
#7
I see what you are getting at. I don't think the script itself should have a cleanup function but xbmc should handle killing the threads gracefully without crashing itself. Try submitting a ticket to trac about this with a testcase.
Reply
#8
Mnuu Wrote:I see what you are getting at. I don't think the script itself should have a cleanup function but xbmc should handle killing the threads gracefully without crashing itself. Try submitting a ticket to trac about this with a testcase.

You had submitted a ticket about this, don't you?

http://trac.xbmc.org/ticket/10160

If I create a Window instance can I get rid of it?
Reply
#9
That turned out to be an unrelated bug. I'm curious, what causes XBMC to halt script execution suddenly? The only thing I can remember that might do that is I saw a function called stopscript in the builtins.
Reply

Logout Mark Read Team Forum Stats Members Help
Multithreading python and XBMC is trouble?0