下面发布的代码启动一个单线程,启动我的macbookpro上的4个核心。 有没有办法限制线程应该使用多少个内核?如何通过线程限制核心数量
import threading
import logging
logging.basicConfig(level=logging.DEBUG, format='(%(threadName)s) %(message)s',)
def func():
logging.debug('starting')
m=0
for i in range(500000000):
m+=i
logging.debug('exiting')
thread = threading.Thread(target=func)
thread.start()
logging.debug('completed')
这里是日志:
Loaded sitecustomize.py
(Thread-1) starting
(MainThread) completed
(Thread-1) exiting
[Finished in 128.0s]
[该文档(https://pythonhosted.org/psutil/#psutil.Process.cpu_affinity)不说它在OSX上可用。 –
是的,它可能无法在Solaris上运行。 –
只有“Linux,Windows,FreeBSD”才被列为支持。 –