Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
engine
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
Container registry
Model registry
Operate
Environments
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
Show more breadcrumbs
AURA
engine
Commits
032ea0ac
Commit
032ea0ac
authored
2 years ago
by
David Trattnig
Browse files
Options
Downloads
Patches
Plain Diff
refact(decorator): store sync lock on instance
parent
fce6e214
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
src/aura_engine/base/lang.py
+12
-9
12 additions, 9 deletions
src/aura_engine/base/lang.py
with
12 additions
and
9 deletions
src/aura_engine/base/lang.py
+
12
−
9
View file @
032ea0ac
...
...
@@ -30,19 +30,22 @@ def synchronized(member):
"""
@synchronized decorator.
Lock a method for synchronized access only.
Lock a method for synchronized access only. The lock is stored to the function or class
instance, depending on what is available.
"""
mutex
=
Lock
()
@wraps
(
member
)
def
wrapper
(
*
args
,
**
vargs
):
def
wrapper
(
*
args
,
**
kwargs
):
lock
=
vars
(
member
).
get
(
"
_synchronized_lock
"
,
None
)
result
=
""
try
:
mutex
.
acquire
()
result
=
member
(
*
args
,
**
vargs
)
mutex
.
release
()
if
lock
is
None
:
lock
=
vars
(
member
).
setdefault
(
"
_synchronized_lock
"
,
Lock
())
lock
.
acquire
()
result
=
member
(
*
args
,
**
kwargs
)
lock
.
release
()
except
Exception
as
e
:
mutex
.
release
()
lock
.
release
()
raise
e
return
result
...
...
@@ -59,7 +62,7 @@ def private(member):
"""
@wraps
(
member
)
def
wrapper
(
*
args
,
**
v
args
):
def
wrapper
(
*
args
,
**
kw
args
):
me
=
member
.
__name__
stack
=
inspect
.
stack
()
calling_class
=
stack
[
1
][
0
].
f_locals
[
"
self
"
].
__class__
.
__name__
...
...
@@ -68,7 +71,7 @@ def private(member):
msg
=
f
'"
{
me
}
(..)
"
called by
"
{
calling_class
}
.
{
calling_method
}
(..)
"
is private
'
print
(
msg
)
raise
Exception
(
msg
)
return
member
(
*
args
,
**
v
args
)
return
member
(
*
args
,
**
kw
args
)
return
wrapper
...
...
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