title: python application freeze on thread.join()
body: <p>I'm writing a simple time tracking application in Python3 and PyQt5. Time is tracked in separate thread. Function that this thread is running doesn't access GUI code. On Windows10 application freezes after trying to close it. It's caused by calling <code>thread.join()</code>. I need to end the process in task manager to close it. On Linux Mint it works fine. I'm using threads from threading library. It doesn't work also with QThread's. If I comment out the <code>thread.join()</code> line it closes without a problem, but the code that's running by this thread doesn't finish.</p>
  
  <p>Thread is initialized in <code>__init__()</code> function of Window class.</p>
  
  <pre><code>self.trackingThread = Thread(target = self.track)
  </code></pre>
  
  <p>Function that is responsible for tracking time:</p>
  
  <pre><code>    def track(self):
      startTime = time()
      lastWindowChangeTime = startTime
      while self.running:
          # check if active window has changed
          if self.active_window_name != get_active_window_name():
              if self.active_window_name in self.applications_time:
                  self.applications_time[self.active_window_name] += int(time() - lastWindowChangeTime) // 60 # time in minutes)
              else:
                  self.applications_time[self.active_window_name] = int(time() - lastWindowChangeTime) // 60  # time in minutes
  
              lastWindowChangeTime = time()
              self.active_window_name = get_active_window_name()
  
  
      totalTime = int(time() - startTime) // 60  # time in minutes
      if date.today() in self.daily_time:
          self.daily_time[date.today()] += totalTime
      else:
          self.daily_time[date.today()] = totalTime
  </code></pre>
  
  <p>Joining the thread:</p>
  
  <pre><code>   def saveAndQuit(self):
          self.running = False
          self.trackingThread.join() # the line that's causing application freeze
          self.save()
          QApplication.instance().quit()
  </code></pre>
  
  <p>EDIT:
  Example:
  <a href="https://pastebin.com/vt3BfKJL" rel="nofollow noreferrer">https://pastebin.com/vt3BfKJL</a></p>
  
  <p>relevant code:</p>
  
  <pre><code>def get_active_window_name():
      active_window_name = ''
  
      if system() == 'Linux':
          active_window_name = check_output(['xdotool', 'getactivewindow', 'getwindowname']).decode('utf-8')
      elif system() == 'Windows':
          window = GetForegroundWindow()
          active_window_name = GetWindowText(window)
  
      return active_window_name
  </code></pre>
  
  <p>EDIT2:
  After removing those 2 lines app closes without any problem. Is there any other way of getting active window name on Windows except win32gui?:</p>
  
  <pre><code>window = GetForegroundWindow()
  active_window_name = GetWindowText(window)
  </code></pre>