为什么python线程消耗这么多内存?为什么python线程消耗这么多内存?
我测量出产生一个线程会消耗8M内存,几乎和全新的python进程一样大!
操作系统:Ubuntu的10.10
编辑:由于大众需求,我会给一些外来的例子,那就是:
from os import getpid
from time import sleep
from threading import Thread
def nap():
print 'sleeping child'
sleep(999999999)
print getpid()
child_thread = Thread(target=nap)
sleep(999999999)
在我的盒子,PMAP PID会给9424K
现在,让我们运行子线程:
from os import getpid
from time import sleep
from threading import Thread
def nap():
print 'sleeping child'
sleep(999999999)
print getpid()
child_thread = Thread(target=nap)
child_thread.start() # <--- ADDED THIS LINE
sleep(999999999)
现在pmap pid会给出17620K
所以,对于额外的线程成本17620K - 9424K = 8196K
即。 87%运行全新的独立流程!
现在是不是只是,错了?
任何人都无法回答这个问题,除非你给我们一些你想要做什么和怎么做的想法。码?使用示例?输入数据? – jathanism 2011-04-12 14:16:35
请参阅http://stackoverflow.com/questions/110259/python-memory-profiler – 2011-04-12 14:17:43
哪个操作系统? – vartec 2011-04-12 14:18:39