Why does a python thread consume so much memory?
I measured that spawning one thread consumes 8 megabytes of memory, almost as big as the whole new python process!
OS: Ubuntu 10.10
Edit: due to popular demand, I will give some extraneous examples, here it is:
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)
In my pmap pid box will give 9424K
Now run the child thread:
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()
Now pmap pid will give 17620K
So, the cost of the additional flow is 17620K - 9424K = 8196K
T. 87% launch of a completely new separate process!
Now this is not so, is it wrong?
Ron
source share