How to pin different processes to individual cpu cores in Python

后端 未结 1 1713
长情又很酷
长情又很酷 2021-01-16 11:13

I\'m writing a Python program that will load a wordlist from a text file and then try unzipping an archive with each word. It wouldn\'t be serious if it didn\'t make use of

相关标签:
1条回答
  • 2021-01-16 11:32

    You can use Pythons multiprocessing by importing import multiprocessing as mp and find out the number of processors by using mp.cpu_count() and should work on most platforms.

    To launch programs/processes on specific CPU cores (in linux) you can use taskset and use this guide as a reference.

    An alternative cross-plattform solution would be to use the psutil package for python.

    However i would suggest you go with a thread/process pooling approach as in my opinion you should let the operating system assign tasks to each cpu/core. You can look at How to utilize all cores with python multiprocessing on how to approach this problem.

    0 讨论(0)
提交回复
热议问题