title: CPython extension using omp freezes Qt UI
body: <p>I am working on a scientific algorithm (image processing), which is written in C++, and uses lots of parallelization, handled by OpenMP. I need it to be callable from Python, so I created a CPython package, which handles the wrapping of the algorithm.
  Now I need some UI, as user interaction is essential for initializing some stuff. My problem is that the UI freezes when I run the algorithm. I start the algorithm in a separate thread, so this shouldn't be a problem (I even proved it by replacing the function call with <code>time.sleep</code>, and it works fine, not causing any freeze). For testing I reduced the UI to two buttons: one for starting the algorithm, and another just to print some random string to console (to check UI interactions).<br />
  I also experienced something really weird. If I started moving the mouse, then pressed the button to start the computation, and after that kept moving the mouse continuously, the UI did not freeze, so hovering over the buttons gave them the usual blueish Windows-style tint. But if I stopped moving my mouse for a several seconds over the application window, clicked a button, or swapped to another window, the UI froze again. It's even more strange that the UI stayed active if I rested my mouse outside of the application window.<br>Here's my code (unfortunately I cannot share the algorithm for several reasons, but I hope I manage to get some help even like this):</p>
  <pre><code>if __name__ == &quot;__main__&quot;:
      from PyQt5.QtWidgets import QApplication, QPushButton, QVBoxLayout, QWidget
      from PyQt5.QtCore import QThread, QObject, pyqtSignal
      import time
      from CustomAlgorithm import Estimator # my custom Python package implemented in C++
  
      class Worker(QObject):
          finished = pyqtSignal()
  
          def run(self):
              estimator = Estimator()
              estimator.calculate()
              # if the above two lines are commented, and the next line is uncommented,
              # everything's fine
              # time.sleep(5)
              print(&quot;done&quot;)
  
      app = QApplication([])
      thread = QThread()
      window = QWidget()
      layout = QVBoxLayout()
      # button to start the calculation
      btn = QPushButton(&quot;start&quot;)
      layout.addWidget(btn)
      btn.clicked.connect(thread.start)
  
      # button to print some text to console
      btn2 = QPushButton(&quot;other button&quot;)
      layout.addWidget(btn2)
      btn2.clicked.connect(lambda: print(&quot;other button clicked&quot;))
      window.setLayout(layout)
  
      # handling events
      worker = Worker(app)
      worker.moveToThread(thread)
      thread.started.connect(worker.run)
      worker.finished.connect(thread.quit)
      worker.finished.connect(worker.deleteLater)
      thread.finished.connect(thread.deleteLater)
      window.show()
      app.exec_()
  </code></pre>
  <p>I tried multiple variants of using threads, like <code>threading.Thread</code>, <code>multiprocessing.Process</code>, <code>PyQt5.QtCore.QThread</code> (as seen above), even <code>napari</code>'s worker implementation, but the result was the same. I even tried removing omp from the code, just in case it interferes somehow with python threads, but it didn't help.</p>
  <p>As for the reason I use python, is that the final goal is to make my implementation available in <code>napari</code>.</p>
  <p>Any help would be highly appreciated!</p>