I have a code that use threading in python. each thread if met a condition will create 2 new threads. now problem is total number of active threads exceeds total number of active threads supported by ubuntu 12.04. now each thread in active thread queue need space to create new threads and then it will terminate. My system have 8 CPUs. now my code is going in deadlock.
Asked
Active
Viewed 114 times
0
-
Note that with CPython there is the Global Interpreter Lock (GIL), which prevents you from processing using all cores. See also [Does python support multiprocessor/multicore programming?](http://stackoverflow.com/questions/203912/does-python-support-multiprocessor-multicore-programming). – Bouke Dec 18 '12 at 11:12
-
I tried multiprocessing but it is consuming all cores leaving system hanged – Pratibha Dec 18 '12 at 11:33
-
What's your question? If your problem is creating too many threads, don't make so many threads... – interjay Dec 18 '12 at 11:39
-
I want to resolve the deadlock issue. and I have to create so many threads. – Pratibha Dec 18 '12 at 11:49
1 Answers
2
You probably shouldn't create so many threads. Instead, use Queue.Queue
s to communicate between different threads.

djc
- 11,603
- 5
- 41
- 54
-
this is a good place to start: http://effbot.org/librarybook/queue.htm – Inbar Rose Dec 18 '12 at 10:53
-
each thread is independent and they dont use any global variable. If I use Queue then I have to push into queue before starting the threads... how can I convert below code to use queue `func(a,i): if a>i): func(a,i+1),func(a-1,i);` I am using threads to deal with 2 independent recursive calls. – Pratibha Dec 18 '12 at 12:06