Skip to content

Examples of DefineSlot and RedefineSlot for python #20839

Closed

Description

@acampove

Explain what you would like to see improved and how.

I am having again problems with multithreading in python because I seem to be using Define and Redefine, which are not thread safe. There seem to be thread safe versions of these methods called DefineSlot and RedefineSlot. However I am struggling to make it work and I cannot find any example of their usage for python.

ROOT version

6.38

Installation method

mamba

Operating system

almalinux9

Additional context

No response

Activity

  1. ferdymercury commented on Jan 14, 2026

    @ferdymercury
    Collaborator
  2. ferdymercury commented on Jan 15, 2026

    @ferdymercury
    Collaborator

    There seem to be thread safe versions of these methods called DefineSlot and RedefineSlot

    DefineSlot and RedefineSlot seem unfortunately not yet supported in Python, but luckily they are just a shortcut for Define, so you can get the same functionality in the meantime using the full expression. For example a thread-safe multi-core Gaussian random number generator:

    import ROOT
    ROOT.gInterpreter.Declare('double myfunctor(UInt_t rdfslot) { static thread_local TRandom3 r3(rdfslot); return r3.Gaus();}')
    rdf = ROOT.RDataFrame(90000000)
    rdf_x = rdf.Define("x", "myfunctor(rdfslot_)")
    h = rdf_x.Histo1D("x")
    h.Draw()
    

    What DefineSlot would do, if it worked with python, would be just that you would have it more compact (no need to spell the first variable rdfslot), so is just a shortcut, nothing more fancy. Side note: You still need to pass though more variables if you have extra arguments in your functor, after rdfslot.

    rdf_x = rdf.DefineSlot("x", "myfunctor")

    Same with RedefineSlot vs Redefine

  3. jainoshika commented on Jan 19, 2026

    @jainoshika

    Hi @ferdymercury, I went through this issue and the forum blog you shared. I want to work on a PR for this and wanted to check with you first if I should add documentation / Python examples for DefineSlot and RedefineSlot as part of the PR, or is there anything specific you would like me to focus on?
    Thanks

  4. 003-kalki commented on Jan 24, 2026

    @003-kalki
    Contributor

    Hi @ferdymercury,
    I’d like to work on this issue. Could you please assign it to me if no one else is currently working on it?

  5. gayatripadalia commented on Apr 4, 2026

    @gayatripadalia

    Hi @ferdymercury,
    I've been looking into this issue and the existing workaround using rdfslot_ with Define. I understand that DefineSlot may not be supported in Python yet.
    Would it be useful if I contribute a clear Python example and documentation demonstrating the thread-safe pattern using rdfslot_, as a practical alternative to DefineSlot for thread-safe column definitions?
    I can start with that, and also explore whether partial support for string-based expressions is feasible - but happy to follow your guidance on what would be most useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions