1

When a function takes several seconds to do its job, you need to use threads in order that the application, created using PyGTK, do not freeze.

However, I do not know what is the best way to write code when many functions should use threads.

I found this answer which shows how to proceed.

Assuming I have 3 different functions, that means I have to do this:

class ThreadFunction1(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.start()

    def run(self):
       # do something1

class ThreadFunction2(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.start()

    def run(self):
       # do something2

class ThreadFunction3(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        self.start()

    def run(self):
       # do something3

And then I could call separately ThreadFunction1(), ThreadFunction2() or ThreadFunction3().

I do not think this is the most elegant way to do, that makes a lot of repetitions. How should I do please?

Community
  • 1
  • 1
Delgan
  • 18,571
  • 11
  • 90
  • 141

0 Answers0