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
3bfa6475
Commit
3bfa6475
authored
3 years ago
by
Robert K
Browse files
Options
Downloads
Patches
Plain Diff
[cleanup][Python] Remove portalocker dependency.
parent
91ea1984
No related branches found
No related tags found
No related merge requests found
Pipeline
#41582
passed with warnings
3 years ago
Stage: test
Stage: downstream
Pipeline: Dune Nightly Test
#41585
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
dune.module
+1
-1
1 addition, 1 deletion
dune.module
pyproject.toml
+1
-1
1 addition, 1 deletion
pyproject.toml
python/dune/common/locking.py
+32
-44
32 additions, 44 deletions
python/dune/common/locking.py
with
34 additions
and
46 deletions
dune.module
+
1
−
1
View file @
3bfa6475
...
...
@@ -4,5 +4,5 @@ Author: The Dune Core developers
Maintainer
:
dune
-
devel
@
lists
.
dune
-
project
.
org
Description
:
Basis
infrastructure
for
all
Dune
modules
URL
:
https
://
gitlab
.
dune
-
project
.
org
/
core
/
dune
-
common
Python
-
Requires
:
pip
>=
21
portalocker
numpy
wheel
jinja2
mpi4py
Python
-
Requires
:
pip
>=
21
numpy
wheel
jinja2
mpi4py
Whitespace
-
Hook
:
Yes
This diff is collapsed.
Click to expand it.
pyproject.toml
+
1
−
1
View file @
3bfa6475
...
...
@@ -10,5 +10,5 @@
# included in the package install from source.
#
[build-system]
requires
=
[
'cmake'
,
'jinja2'
,
'mpi4py'
,
'ninja'
,
'numpy'
,
'pip>
=
21.0
.
0
',
'
portalocker
',
'
requests
', '
scikit-build
', '
setuptools
', '
wheel
']
requires
=
[
'cmake'
,
'jinja2'
,
'mpi4py'
,
'ninja'
,
'numpy'
,
'pip>
=
21.0
.
0
', '
requests
', '
scikit-build
', '
setuptools
', '
wheel
']
build-backend
=
'setuptools.build_meta'
This diff is collapsed.
Click to expand it.
python/dune/common/locking.py
+
32
−
44
View file @
3bfa6475
## By default use portalocker, if available.
## However, portalocker is not available on all systems
## and therefore a fallback implementation is also provided
try
:
from
portalocker
import
Lock
as
_Lock
from
portalocker.constants
import
LOCK_EX
,
LOCK_SH
class
Lock
(
_Lock
):
def
__init__
(
self
,
path
,
flags
,
*
args
,
**
kwargs
):
_Lock
.
__init__
(
self
,
path
,
*
args
,
flags
=
flags
,
timeout
=
None
,
**
kwargs
)
except
ModuleNotFoundError
:
## Fallback implementation if portalocker was not found
## This is still needed! Do not remove it.
import
os
import
fcntl
from
fcntl
import
LOCK_EX
,
LOCK_SH
# file locking from fcntl
def
lock_file
(
f
,
cmd
=
fcntl
.
LOCK_EX
):
fcntl
.
flock
(
f
,
cmd
)
return
f
def
unlock_file
(
f
):
fcntl
.
flock
(
f
,
fcntl
.
LOCK_UN
)
return
f
import
os
import
fcntl
from
fcntl
import
LOCK_EX
,
LOCK_SH
# file locking from fcntl
def
lock_file
(
f
,
cmd
=
fcntl
.
LOCK_EX
):
fcntl
.
flock
(
f
,
cmd
)
return
f
def
unlock_file
(
f
):
fcntl
.
flock
(
f
,
fcntl
.
LOCK_UN
)
return
f
# 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
=
'
w+
'
,
*
args
,
**
kwargs
)
# Lock the opened file
self
.
file
=
lock_file
(
self
.
file
,
flags
)
# flags are either LOCK_EX or LOCK_SH
# 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
=
'
w+
'
,
*
args
,
**
kwargs
)
# Lock the opened 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
# Return the opened file object (knowing a lock has been obtained).
def
__enter__
(
self
,
*
args
,
**
kwargs
):
return
self
.
file
# Unlock the file and close the file object.
def
__exit__
(
self
,
exc_type
=
None
,
exc_value
=
None
,
traceback
=
None
):
# Flush to make sure all buffered contents are written to file.
self
.
file
.
flush
()
os
.
fsync
(
self
.
file
.
fileno
())
# Release the lock on the 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.
return
exc_type
==
None
# Unlock the file and close the file object.
def
__exit__
(
self
,
exc_type
=
None
,
exc_value
=
None
,
traceback
=
None
):
# Flush to make sure all buffered contents are written to file.
self
.
file
.
flush
()
os
.
fsync
(
self
.
file
.
fileno
())
# Release the lock on the 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.
return
exc_type
==
None
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