Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dune-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Core Modules
dune-common
Commits
c6d6eda8
Commit
c6d6eda8
authored
5 years ago
by
Robert K
Browse files
Options
Downloads
Patches
Plain Diff
[bugfix][builder] Added shared lock for portalocker replacement.
parent
cdbd6677
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!790
Feature/add python bindings
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
builder.py
+9
-10
9 additions, 10 deletions
builder.py
with
9 additions
and
10 deletions
builder.py
+
9
−
10
View file @
c6d6eda8
...
...
@@ -16,26 +16,25 @@ try:
from
portalocker
import
Lock
from
portalocker.constants
import
LOCK_EX
,
LOCK_SH
except
ModuleNotFoundError
:
# Posix based file locking (Linux, Ubuntu, MacOS, etc.)
import
fcntl
from
fcntl
import
LOCK_EX
,
LOCK_SH
def
lock_file
(
f
):
fcntl
.
lockf
(
f
,
fcntl
.
LOCK_EX
)
# file locking from fcntl
def
lock_file
(
f
,
cmd
=
fcntl
.
LOCK_EX
):
fcntl
.
flock
(
f
,
cmd
)
return
f
def
unlock_file
(
f
):
fcntl
.
lockf
(
f
,
fcntl
.
LOCK_UN
)
fcntl
.
flock
(
f
,
fcntl
.
LOCK_UN
)
return
f
# Class for ensuring that all file operations are atomic, treat
# initialization like a standard call to 'open' that happens to be atomic.
# This file opener *must* be used in a "with" block.
class
Lock
:
# Open the file with arguments provided by user. Then acquire
# a lock on that file object (WARNING: Advisory locking).
def
__init__
(
self
,
path
,
flags
,
*
args
,
**
kwargs
):
# Open the file and acquire a lock on the file before operating
self
.
file
=
open
(
path
,
mode
=
'
a
'
,
*
args
,
**
kwargs
)
self
.
file
=
open
(
path
,
mode
=
'
w+
'
,
*
args
,
**
kwargs
)
# Lock the opened file
lock_file
(
self
.
file
)
self
.
file
=
lock_file
(
self
.
file
,
flags
)
# flags are either LOCK_EX or LOCK_SH
# Return the opened file object (knowing a lock has been obtained).
def
__enter__
(
self
,
*
args
,
**
kwargs
):
return
self
.
file
...
...
@@ -46,7 +45,7 @@ except ModuleNotFoundError:
self
.
file
.
flush
()
os
.
fsync
(
self
.
file
.
fileno
())
# Release the lock on the file.
unlock_file
(
self
.
file
)
self
.
file
=
unlock_file
(
self
.
file
)
self
.
file
.
close
()
# Handle exceptions that may have come up during execution, by
# default any exceptions are raised to the user.
...
...
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