python thread.error: can’t start new thread

Posted on March 5, 2010. Filed under: Python | Tags: , , , |

The python has thread.error such as:

File "/usr/lib/python2.5/threading.py", line 440, in start
_start_new_thread(self.__bootstrap, ())
thread.error: can't start new thread

The “can’t start new thread” error almost certainly due to the fact that you have already have too many threads running within your python process, and due to a resource limit of some kind the request to create a new thread is refused.

You should probably look at the number of threads you’re creating(maybe in the /proc/pid/); the maximum number you will be able to create will be determined by your environment, but it should be in the order of hundreds at least. (Can try ulimit to solve this issue)

It would probably be a good idea to re-think your architecture here; seeing as this is running asynchronously anyhow, perhaps you could use a pool of threads to fetch resources from another site instead of always starting up a thread for every request.

Another improvement to consider is your use of Thread.join and Thread.stop; this would probably be better accomplished by providing a timeout value to the constructor.

Reference:

http://stackoverflow.com/questions/1834919/error-cant-start-new-thread

http://adywicaksono.wordpress.com/2007/07/10/i-can-not-create-more-than-255-threads-on-linux-what-is-the-solutions/

http://www.afnog.org/archives/2008-September/004535.html

http://rcsg.rice.edu/rcsg/shared/ulimit.html

http://answers.google.com/answers/threadview/id/311442.html

http://ubuntuforums.org/archive/index.php/t-114071.html

Read Full Post | Make a Comment ( 2 so far )

Some multithreading tutorial URLs

Posted on June 6, 2007. Filed under: C/C++, Linux, Programming, Windows | Tags: , , , , , |

C

POSIX Threads Tutorial

http://math.arizona.edu/~swig/documentation/pthreads/

POSIX thread (pthread) libraries

http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html

C++

Multithreading Tutorial(Mutex, deadlock, livelock, scoped lock, Read/Write lock, Monitor Object, Active Object, boost) — Good!

http://www.paulbridger.com/multithreading_tutorial/

Multithreading Tutorial (mainly on Win32)

http://www.codeproject.com/KB/threads/MultithreadingTutorial.aspx

C++/CLI Threading

Part I:

http://www.drdobbs.com/windows/184402018

Part II:

http://www.drdobbs.com/windows/184402029

Threads in C++

http://www.linuxselfhelp.com/HOWTO/C++Programming-HOWTO-18.html

Read Full Post | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...