threads and memory

Ivan Voras ivoras at __yahoo__.com_
Tue Feb 7 14:51:59 EST 2006


Lee Leahu wrote:

> However, I have encountered the following error after I have started my 381st thread:

This number (actually, ~380) is suspicious when seen with threads 
because it almost always means running out of process address space. As 
threads are part of a single process, and that process has (usually 
today) 32bit address space, and modern Linux systems allocate huge 
amounts of memory per-thread (8 MB for threads' stack!), and the kernel 
reserves ~1MB in the address space for itself, you can easily reach > 
4GB of total allocated memory.

This *doesn't* mean you are actually using 4GB of memory (i.e. storing 
values to it), only that the process gets "assigned" this memory. Python 
doesn't support specifying thread attributes AFAIK, so you should find a 
way to specify default thread stack size, possibly with an environment 
variable (see manual page for "pthread" library calls). Try 64k - your 
task seems simple enough :)




More information about the Python-list mailing list