Skip to content

Add Python example for thread-safe Define using rdfslot_#21798

Open
gayatripadalia wants to merge 1 commit intoroot-project:masterfrom
gayatripadalia:patch-1
Open

Add Python example for thread-safe Define using rdfslot_#21798
gayatripadalia wants to merge 1 commit intoroot-project:masterfrom
gayatripadalia:patch-1

Conversation

@gayatripadalia
Copy link
Copy Markdown

Summary

This PR adds a Python tutorial demonstrating a thread-safe pattern
using rdfslot_ in ROOT RDataFrame.

In C++, ROOT provides DefineSlot and RedefineSlot for thread-safe
operations. However, these APIs are currently not available in Python.

This example shows how rdfslot_ can be used as a practical and safe
workaround to achieve thread-local computation in a multi-threaded
environment.

This contribution serves as a practical Python-side alternative until native support becomes available.

Motivation

Issue #20839 highlights the lack of Python examples for thread-safe operations similar to DefineSlot.

This contribution aims to:

  • Provide a clear and minimal Python example
  • Help users understand slot-based computation
  • Offer a practical workaround using existing features

Changes Made

  • Added new tutorial:
    tutorials/analysis/dataframe/df_python_threadsafe_example.py
  • Demonstrates:
    • Enabling implicit multi-threading
    • Using rdfslot_ to identify thread/slot
    • Performing safe, thread-local computations
  • Includes inline explanations for beginner accessibility

Testing

  • The script runs successfully with ROOT Python bindings
  • Output verifies correct usage of rdfslot_ across threads
  • No external dependencies required

Notes for Reviewers

  • The example is intentionally simple and educational
  • Designed to be beginner-friendly while demonstrating correct usage
  • Does not attempt to reimplement DefineSlot, but provides a practical alternative

Related Issue

Closes #20839

Adds a tutorial demonstrating a thread-safe pattern in Python using rdfslot_,
as a workaround for DefineSlot which is not available in Python.
Closes root-project#20839
@gayatripadalia gayatripadalia requested a review from couet as a code owner April 5, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Examples of DefineSlot and RedefineSlot for python

1 participant