I have some trouble using threading and scipy.stats.randint module. Indeed, when several threads are launched, a local array (bootIndexs in the code below) seems to be used for all launched thread.
This is the raised Error
> Exception in thread Thread-559:
Traceback (most recent call last):
...
File "..\calculDomaine3.py", line 223, in bootThread
result = bootstrap(nbB, distMod)
File "...\calculDomaine3.py", line 207, in bootstrap
bootIndexs = spstats.randint.rvs(0, nbTirages-1, size = nbTirages)
File "C:\Python27\lib\site-packages\scipy\stats\distributions.py", line 5014, in rvs
return super(rv_discrete, self).rvs(*args, **kwargs)
File "C:\Python27\lib\site-packages\scipy\stats\distributions.py", line 582, in rvs
vals = reshape(vals, size)
File "C:\Python27\lib\site-packages\numpy\core\fromnumeric.py", line 171, in reshape
return reshape(newshape, order=order)
ValueError: total size of new array must be unchanged
And this is my code :
import threading
import Queue
from scipy import stats as spstats
nbThreads = 4
def test(nbBoots, nbTirages, modules ):
def bootstrap(nbBootsThread, distribModules) :
distribMax = []
for j in range(nbBootsThread):
bootIndexs = spstats.randint.rvs(0, nbTirages-1, size = nbTirages)
boot = [distribModules[i] for i in bootIndexs]
distribMax.append(max(boot))
return distribMax
q = Queue.Queue()
def bootThread (nbB, distMod):
result = bootstrap(nbB, distMod )
q.put(result, False)
q.task_done()
works = []
for i in range(nbThreads) :
works.append(threading.Thread(target = bootThread, args = (nbBoots//nbThreads, modules[:],) ))
for w in works:
w.daemon = True
w.start()
q.join()
distMaxResult = []
for j in range(q.qsize()):
distMaxResult += q.get()
return distMaxResult
class classTest:
def __init__(self):
self.launch()
def launch(self):
print test(100, 1000, range(1000) )
Thanks for your answers.
nbThreadtonbThreads) and I am getting a different error (Exception in thread Thread-4 (most likely raised during interpreter shutdown)).scipyfrom the script, and still get the exception.