Hi folks,

Over the years we've used more and more threads in OpenLP for running things like web servers, downloads and other things that need to happen concurrently with the UI. Unfortunately because everything has been in bits and in various places, we've never had a unified way to run and keep track of threads. Thankfully we've largely not run into many issues, but more recently there have been segfaults not just when OpenLP stopped, but also preventing OpenLP from starting.

With this in mind I refactored how we run threads in OpenLP:

  from openlp.core.threading import ThreadWorker, run_thread

  class Worker(ThreadWorker):
      def start(self):
          """
          Do your stuff in here, then emit the quit signal.
          """
          self.server = Server()
          self.server.run()
          self.quit.emit()

      def stop(self):
          """
If your thread is long-running, this is how OpenLP will stop it
          if it is still running when the user exits OpenLP.
          """
          self.server.stop()



  class MyClass(object):
      def run_server(self):
          """
          Run the server in a thread
          """
          worker = Worker()
          run_thread(worker, 'my_server')


I have also put together a wiki page explaining the threads API:

  https://wiki.openlp.org/Development:Threads


This change is not in trunk at the time of this e-mail, but the merge proposal is on Launchpad:

https://code.launchpad.net/~raoul-snyman/openlp/better-threading/+merge/335801


--
Raoul Snyman
+1 (520) 490-9743
[email protected]
_______________________________________________
openlp-dev mailing list
[email protected]
https://lists.openlp.io/mailman/listinfo/openlp-dev

Reply via email to