2

I am creating a GUI multithreading application with Python3. After a while playing with it is starting to go slower and slower and the number of threads is increasing a lot.

I am using htop to see the number of threads and also the name, but all of them appear as "python3" so I can not distinguish them.

I have something like:

myapp
  |_ python3
  |_ python3
  |_ python3
  ...

I am creating the threads in this way:

recorder = Thread(target=self.record, name='recorder')
recorder.start()
requester = Thread(target=self.run, name='requester')
requester.start()

So in the tree view of htop I spected to see something like:

myapp
  |_ recorder
  |_ requester
  ...

Should I create the threads in a different way? What am I missing?

Ana
  • 177
  • 1
  • 13
  • Perhaps show snippets of what is `self.record` and `self.run`? – Axois Aug 29 '19 at 13:57
  • 1
    @Axios I don't think that would help – Peter Wood Aug 29 '19 at 13:58
  • 1
    @Axois it is just the thread code. The recorder is writing data in a csv file and the run method is reading from a socket. Is it important? – Ana Aug 29 '19 at 14:03
  • Your way of calling of calling threads seems fine. However I would suggest to `.join()` the threads after calling `.start()` which is a good idea if your threads arent daemon. However for the slowing part, im suspecting its due to the operations of your functions, but @PeterWood thinks otherwise, so I'm not sure either :). – Axois Aug 29 '19 at 14:23
  • 1
    Check out this existing answer: [Python thread name doesn't show up on ps or htop](https://stackoverflow.com/questions/34361035/python-thread-name-doesnt-show-up-on-ps-or-htop) – Mark A Aug 29 '19 at 16:45

0 Answers0