Here's MWE much more code that I use. It performs Monte Carlo integration according to KDE ( kernel density estimate ) for all values โโbelow a certain threshold (the integration method was proposed in this question: Integration of a 2D kernel density estimate ) iteratively for several points in the list and returns a list of these results.
import numpy as np from scipy import stats from multiprocessing import Pool import threading
Multiprocessing was suggested in the code in this question. Accelerate the kernel evaluation sample to speed up the code (up to ~ 3.4x).
The code works fine until I try to pass a list of more than 62-63 elements to the KDE function (i.e.: I set the value to more than 63 in the for i in range(100) ). If I do this, I get the following error:
Traceback (most recent call last): File "~/gauss_kde_temp.py", line 78, in <module> print 'Integral result: ', kde_integration(m_list) File "~/gauss_kde_temp.py", line 48, in kde_integration pool = Pool(processes=cores) File "/usr/lib/python2.7/multiprocessing/__init__.py", line 232, in Pool return Pool(processes, initializer, initargs, maxtasksperchild) File "/usr/lib/python2.7/multiprocessing/pool.py", line 144, in __init__ self._worker_handler.start() File "/usr/lib/python2.7/threading.py", line 494, in start _start_new_thread(self.__bootstrap, ()) thread.error: can't start new thread
usually (9 out of 10 times) around the active thread 374 . I got out of my league in terms of python coding here, and I have no idea how I can fix this problem. Any help would be greatly appreciated.
Add
I tried adding a while to prevent using too many code streams. I did replace the string print threading.active_count() with this bit of code:
# Print number of active threads. exit_loop = True while exit_loop: if threading.active_count() < 300: exit_loop = False else:
When 302 active threads are reached, the code stops (i.e., gets stuck inside the loop). I waited more than 10 minutes, and the code never left the loop, and the number of active threads never dropped from 302 . Shouldn't the number of active threads decrease after some time?
python multithreading numpy montecarlo kernel density
Gabriel
source share