0

I am working on a python agent and want to get the number of active threads in the current python virtual machine. So far, I simply traverse all the processes and count their threads.

ps = [psutil.Process()]
count = 0

    while len(ps) > 0:
        p = ps[0]
        ps.pop(0)
        count += len(p.threads())
        ps += p.children()

Is there a more appropriate way?

jieke
  • 1
  • 1
  • 3

0 Answers0