Kodi Community Forum
Any good tutorial on python 3 threading? - Printable Version

Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32)
+--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26)
--- Thread: Any good tutorial on python 3 threading? (/showthread.php?tid=355455)

Any good tutorial on python 3 threading? - scott967 - 2020-06-25

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.

RE: Any good tutorial on python 3 threading? - V8MEM - 2020-06-26

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

RE: Any good tutorial on python 3 threading? - Roman_V_M - 2020-06-26

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?

RE: Any good tutorial on python 3 threading? - scott967 - 2020-07-01

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.

This forum uses Lukasz Tkacz MyBB addons.