Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cc-server
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor 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
Mirror
cc-server
Commits
2550bca6
Commit
2550bca6
authored
14 years ago
by
Antoine Millet
Browse files
Options
Downloads
Patches
Plain Diff
Added AcquiresAllOrNone class in utils.
parent
05c4197d
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ccserver/utils.py
+27
-0
27 additions, 0 deletions
ccserver/utils.py
with
27 additions
and
0 deletions
ccserver/utils.py
+
27
−
0
View file @
2550bca6
...
...
@@ -5,6 +5,8 @@
Some helpers used by cc-server.
'''
from
threading
import
Lock
class
Acquires
(
object
):
'''
...
...
@@ -34,3 +36,28 @@ class Acquires(object):
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
for
lock
in
self
.
_locks
:
lock
.
release
()
class
AcquiresAllOrNone
(
Acquires
):
'''
Class that extend Acquires to allow to release all lock if one of them
is not free.
'''
# Global acquire lock:
acquirelock
=
Lock
()
def
__enter__
(
self
):
while
True
:
with
self
.
acquirelock
:
acquired
=
[]
for
lock
in
self
.
_locks
:
if
not
lock
.
acquire
(
False
):
for
lock_acquired
in
acquired
:
lock_acquired
.
release
()
break
else
:
acquired
.
append
(
lock
)
else
:
break
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