Hi,
I’d like to execute some C++ workload in parallel in multiple threads, and steer everything from python.
Below is what I have so far. It seems that threads run sequentially, however.
I suppose that’s because PyROOT
does not release the GIL? If I run time.sleep(2)
instead of the C++ function threads do run concurrently.
How can I convince the threads to run concurrently in this scenario?
Cheers,
Enrico
import ROOT
from threading import Thread
from time import sleep
from collections import deque
ROOT.gInterpreter.Declare("""
void foo() { for (int i=0; i < 1000000000; ++i)
;
std::cout << "done" << std::endl; }
""")
ROOT.ROOT.EnableImplicitMT()
threads = [Thread(target=ROOT.foo) for _ in range(ROOT.ROOT.GetImplicitMTPoolSize())]
deque(map(Thread.start, threads))
deque(map(Thread.join, threads))
ROOT Version: master
Platform: linux