0

In Java, this will return the number of available processors:

Runtime.getRuntime().availableProcessors()

This is handy when deciding how many long running threads to create.

Is there an equivalent function to call in Python?

dstrube
  • 193
  • 1
  • 6
  • 17
  • Ack! I was looking through stackoverflow for days trying to find that. I was finding it hard to believe that no one had asked this already. Thank you Ruturaj! – dstrube Apr 10 '19 at 12:29

2 Answers2

1

With python 2.6 or greater ,

multiprocessing.cpu_count()
Srinivasan Sekar
  • 2,049
  • 13
  • 22
1

Here you go, there are definitely duplicate answers out there

import os
os.cpu_count()
D.Sanders
  • 98
  • 6