Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
Root
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
为了安全,强烈建议开启2FA双因子认证:User Settings -> Account -> Enable two-factor authentication!!!
Show more breadcrumbs
cxwx
Root
Commits
7768b4ea
Commit
7768b4ea
authored
3 years ago
by
Vincenzo Eduardo Padulano
Browse files
Options
Downloads
Patches
Plain Diff
[PyROOT] Add __reduce__ method to ROOTFacade to help serialization tools
parent
a0ce07bf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bindings/pyroot/pythonizations/python/ROOT/_facade.py
+41
-1
41 additions, 1 deletion
bindings/pyroot/pythonizations/python/ROOT/_facade.py
with
41 additions
and
1 deletion
bindings/pyroot/pythonizations/python/ROOT/_facade.py
+
41
−
1
View file @
7768b4ea
import
importlib
import
types
import
sys
import
os
...
...
@@ -75,6 +76,17 @@ def _create_rdf_experimental_distributed_module(parent):
return
experimental
def
_subimport
(
name
):
# type: (str) -> types.ModuleType
"""
Import and return the Python module with the input name.
Helper function for the __reduce__ method of the ROOTFacade class.
"""
return
importlib
.
import_module
(
name
)
class
ROOTFacade
(
types
.
ModuleType
):
"""
Facade class for ROOT module
"""
...
...
@@ -253,13 +265,41 @@ class ROOTFacade(types.ModuleType):
logons
=
[
os
.
path
.
join
(
str
(
self
.
TROOT
.
GetEtcDir
()),
'
system
'
+
name
),
os
.
path
.
expanduser
(
os
.
path
.
join
(
'
~
'
,
name
))
]
]
if
logons
[
-
1
]
!=
os
.
path
.
join
(
os
.
getcwd
(),
name
):
logons
.
append
(
name
)
for
rootlogon
in
logons
:
if
os
.
path
.
exists
(
rootlogon
):
self
.
TApplication
.
ExecuteFile
(
rootlogon
)
def
__reduce__
(
self
):
# type: () -> types.ModuleType
"""
Reduction function of the ROOT facade to customize the (pickle)
serialization step.
Defines the ingredients needed for a correct serialization of the
facade, that is a function that imports a Python module and the name of
that module, which corresponds to this facade
'
s __name__ attribute. This
method helps serialization tools like `cloudpickle`, especially used in
distributed environments, that always need to include information about
the ROOT module in the serialization step. For example, the following
snippet would not work without this method::
import ROOT
import cloudpickle
def foo():
return ROOT.TH1F()
cloudpickle.loads(cloudpickle.dumps(foo))
In particular, it would raise::
TypeError: cannot pickle
'
ROOTFacade
'
object
"""
return
_subimport
,
(
self
.
__name__
,)
# Inject version as __version__ property in ROOT module
@property
def
__version__
(
self
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment