Any good tutorial on python 3 threading?
#1
I'm trying to run down a problem updating an orphaned script for python3/matrix.  It runs on 18.  The problem is in the threading (at this point I haven't studied the existing code enough to understand the design).  But the problem is it's doing a thread.join and then later an .event and that's throwing an exception in threading having to do with locks when I run it in matrix.  A side issue is I've added an xbmc.Monitor() object to abort the script on profile/Kodi exit.  I don't know if that is the cause of the new exception.  I found some search results with possible issues on python 3 along these lines, but can't get further without having a better understanding about how threading model works in Py 3.  I was hoping someone could direct me to a good resource, to avoid random searching.

scott s.
.
Reply
#2
You would need to send a shutdown signal from monitor to every thread and clean them up before the monitor exit. Basically every thread polls a threading.Event and has strict less than 5s timeouts on IO so that they don't wait for some Queue or HTTP indefinitely
Reply
#3
As far as I know, there was no major changing in threading API in Python 3 compared to Python 2 (except for removing the low-level thread module). Could you give examples of the problematic code and the errors that you are getting?
Reply
#4
I found the problem, it was kind of insidious.  The addon creates a Timer subclass of threading.Thread.  That Thread subclass defines an attribute self._stop to create an event object that was set in the Timer's stop method.  Somehow that was causing problems in the threading.Thread.join method (tried to set the event).  Just renaming the attribute to _xstop solved it.  Not sure why.

scott s.
.
Reply

Logout Mark Read Team Forum Stats Members Help
Any good tutorial on python 3 threading?0