How to terminate sibling threads?
#1
Code:
class th(Thread):
  def __init__ (self):
    Thread.__init__(self)
  def run(self):
    while True:
      time.sleep(1)

th().start()
while True:
  time.sleep(1)

Thought i should ask about this before making a ticket. Consider the small example above; how do you terminate th when 'self' is being stopped?
Because xbmc complains "not the last thread" and crashes. Probably because it just terminates self, i dont know..
Reply
#2
you need to ASK the thread to die. you cannot terminate another thread (at least not in any non-fugly way).
Reply
#3
Could you give me a sample addon for that? xbmc should not crash... (it should hang indefinetly).
<edit> just realized you had all code there </edit>
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#4
ventech Wrote:
Code:
class th(Thread):
  def __init__ (self):
    Thread.__init__(self)
  def run(self):
    while True:
      time.sleep(1)

th().start()
while True:
  time.sleep(1)

Thought i should ask about this before making a ticket. Consider the small example above; how do you terminate th when 'self' is being stopped?
Because xbmc complains "not the last thread" and crashes. Probably because it just terminates self, i dont know..


Main thread do start thread2 and do signal over __exitFlag__ that the
thread should terminate ....


Here comes the main-loop part as example :

Code:
# Starting worker-thread

                   thread2 = GUIWorkerThread()
                   thread2.start()

                   GUIlog ("create main-menu")
                   xbmc.executebuiltin("Dialog.Close(busydialog)")
                   menu01 = GUIMain01Class()
                   del menu01
                   __exitFlag__ = 1

                   # By now, we must wait until thread2 do exit

                   while thread2.isAlive():
                         time.sleep(1)
                         GUIlog ("waiting for termination of thread2")



Here comes the thread2 class :
Code:
#########################################################
# Class     : GUIWorkerThread                           #
#########################################################
# Parameter : none                                      #
# Returns   : none                                      #
#########################################################
class GUIWorkerThread(threading.Thread):

        def __init__(self):
            threading.Thread.__init__(self)        
        def run(self):
            exit = True
            if (__verbose__ == "true"):  
                GUIlog('[W-Thread] starting ...')
            else:
                GUIlog('[W-Thread] starting ...')
            while (exit):  
                   if (__exitFlag__ == 1):
                       exit = False
                   time.sleep(1)
                   if (__verbose__ == "true"):  
                       GUIlog('[W-Thread] is active and running ...')
                   if (__ProgressView__ == False):
                       if (__jobs__ == True):
                           if (__verbose__ == "true"):  
                              GUIlog('[W-Thread] active jobe is running .....')
            if (__verbose__ == "true"):  
                GUIlog('[W-Thread] do exit now ...')
            else:
                GUIlog('[W-Thread] do exit now ...')
            thread.exit()          
                    
#########################################################

You have to define the var __exitFlag__ inside the global section of the code
Reply

Logout Mark Read Team Forum Stats Members Help
How to terminate sibling threads?0