RDataFrame multithreading seg. faults with python for loops?

HI all,

My code seems to seg. fault, when using RDataFrame’s multithreading and working with multiple histograms.

Here is a small reproducible:

import ROOT
# comment next line and everything works
ROOT.EnableImplicitMT()


df = ROOT.RDataFrame(10)\
         .Define("x", "rdfentry_")\
         .Define("x2", "rdfentry_*rdfentry_")

vars = ["x", "x2"]

histos = []
for var in vars:
    h = df.Histo1D(("h_{}".format(var), "{}; x; y".format(var), 100, 0, 100), var)
    histos.append(h)

for var, h in zip(vars, histos):
    canvas = ROOT.TCanvas("{}".format(var))
    h.Draw()
    canvas.Update()
    input("Press something to get the next histogram")

Is that “expected behaviour”, because my code is not thread safe somehow? Or is it a bug?
If it’s my code problem, could somebody explain why and how to avoid it?

Full stack trace of seg. fault is attached in the txt file.
stacktrace.txt (53.4 KB)

cheers,
Bohdan

ROOT Version: 6.26/06
Platform: Centos 7
Compiler: gcc 11.2
Python: 3.9.10

Hello @FoxWise ,

I don’t know what is causing the crash, but as you can see from the stacktrace and the output of the reproducer the crash is not in RDataFrame but rather in the graphics, and it happens after the RDF event loop has already completed.

Here’s another version of the reproducer where the crash happens (might need to run the repro a few times) after the RDataFrame has already gone out of scope:

import ROOT
# comment next line and everything works
ROOT.EnableImplicitMT()

vars = ["x", "x2"]
    

def get_histos():
    df = ROOT.RDataFrame(10)\
             .Define("x", "rdfentry_")\
             .Define("x2", "rdfentry_*rdfentry_")
    
    histos = []
    for var in vars:
        h = df.Histo1D(("h_{}".format(var), "{}; x; y".format(var), 100, 0, 100), var)
        histos.append(h)
    # event loop runs here
    histos = [h.GetValue() for h in histos]
    return histos

histos = get_histos()
for var, h in zip(vars, histos):
    canvas = ROOT.TCanvas("{}".format(var))
    h.Draw()
    canvas.Update()
    input("Press something to get the next histogram")

As a workaround it looks like running the script under python -i works.

You might want to open an issue at Issues · root-project/root · GitHub . cc: @Axel .

Cheers,
Enrico

1 Like

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