Skip to content

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

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

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

Conversation

@gayatripadalia
Copy link
Copy Markdown

@gayatripadalia gayatripadalia commented Apr 5, 2026

Summary

This PR adds a Python tutorial demonstrating thread-safe patterns in ROOT RDataFrame using rdfslot_.
In C++, ROOT provides DefineSlot and RedefineSlot for thread-safe operations by exposing the slot index to user-defined callables. These APIs are currently not available in PyROOT.

This tutorial shows how to reproduce the same behavior in Python by explicitly forwarding rdfslot_, enabling safe and lock-free access to per-slot resources in multi-threaded workflows.

Motivation

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

This contribution provides a practical Python example of slot-based computation and demonstrates safe usage of mutable state in multi-threaded RDataFrame workflows, reflecting the design and intent of DefineSlot using existing PyROOT features.

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
Copy link
Copy Markdown
Member

@vepadulano vepadulano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dear @gayatripadalia ,

Thanks for attempting to increase the coverage of our suite of tutorials! The need to have more thread-safe examples is understood. Nonetheless, this PR does not contribute enough in that direction. Your example does not use the rdfslot_ implicit column in any meaningful manner, and it does not include examples of DefineSlot with comments motivating why that operation would be needed.

Improve rdfslot_ tutorial with thread-safe use cases.
@gayatripadalia
Copy link
Copy Markdown
Author

Dear @vepadulano,
Thank you for your helpful feedback.
I’ve updated the PR to better demonstrate meaningful usage of rdfslot_, including clearer examples of per-slot resource handling and explanations motivating thread-safe patterns similar to DefineSlot.
I wanted to check if the current version now aligns with what you had in mind, or if you would suggest any further improvements, especially regarding the examples or level of detail.
Thanks again for your guidance.

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

2 participants