I'm using Mayavi2 mlab module for some scientific visualisation. There are about 100k files, I want to visualise and save as images, to assemble them in gif animation later. To speed up such visualisation, I am going to use multiprocessing module. The simple example is below.
from mayavi import mlab
def test_plot3d(dummy):
mlab.options.offscreen = True
l = mlab.plot3d([1,2], [1,2], [1,2])
mlab.savefig(str(dummy)+".png")
mlab.close()
from multiprocessing import Pool
NP = 2
pool = Pool(NP,maxtasksperchild=1)
res = pool.imap(test_plot3d,[x for x in xrange(0,4000)])
for r in res:
print "OK"
print "FINISH"
When NP is 2, it is all ok. When NP is >2, the next error appears:
[xcb] Unknown sequence number while processing queue [xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
The programm produces some images, but it hangs on others, so it never finishes. Google told me, that this is about GTK and multithreading, but I specified maxtasksperchild for pool as 1, that should mean the one task per process, and then it will be restarted, and there will be only one mayavi instance on each process (but it does not happen, as I can see).
So the question is how to properly start a pool of processes for parallel mayavi visualisation ?