Running C++ functions in parallel with python multithreading: does PyROOT release the GIL?

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?


import ROOT
from threading import Thread
from time import sleep
from collections import deque

    void foo() { for (int i=0; i < 1000000000; ++i)
    std::cout << "done" << std::endl; }

threads = [Thread( for _ in range(ROOT.ROOT.GetImplicitMTPoolSize())]
deque(map(Thread.start, threads))
deque(map(Thread.join, threads))

ROOT Version: master
Platform: linux

There is an attribute of MethodProxys called _threaded:

      { (char*)"_threaded", (getter)mp_getthreaded, (setter)mp_setthreaded,
            (char*)"If true, releases GIL on call into C++", NULL },

You can try setting it to True for

It works, thanks!
Adding = True the runtime of the last three lines decreases from ~14.5 seconds to ~2.5 on my 8 core machine.


is this documented anywhere? :smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.