Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ebpfCAT
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
Show more breadcrumbs
karaboDevices
ebpfCAT
Commits
2f590b0a
Commit
2f590b0a
authored
3 months ago
by
Martin Teichmann
Browse files
Options
Downloads
Patches
Plain Diff
use os module for lock file opening, not builtin open
parent
d6861e58
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
ebpfcat/lock.py
+16
-5
16 additions, 5 deletions
ebpfcat/lock.py
with
16 additions
and
5 deletions
ebpfcat/lock.py
+
16
−
5
View file @
2f590b0a
...
...
@@ -4,21 +4,22 @@ from asyncio import Lock, sleep
class
LockFile
:
"""
A lock file for all mailboxes in an EtherCAT loop
"""
def
__init__
(
self
,
filename
,
minimum
,
maximum
):
self
.
filename
=
filename
self
.
minimum
=
minimum
self
.
maximum
=
maximum
os
.
makedirs
(
filename
.
rsplit
(
'
/
'
,
1
)[
0
],
exist_ok
=
True
)
try
:
self
.
file
=
open
(
self
.
filename
,
'
xb
'
)
self
.
fd
=
os
.
open
(
self
.
filename
,
os
.
O_CREAT
|
os
.
O_RDWR
|
os
.
O_EXCL
|
os
.
O_CLOEXEC
)
except
FileExistsError
:
self
.
f
ile
=
open
(
self
.
filename
,
'
r+b
'
)
self
.
f
d
=
os
.
open
(
self
.
filename
,
os
.
O_RDWR
|
os
.
O_CLOEXEC
)
else
:
self
.
file
.
write
(
bytes
(
maximum
-
minimum
))
self
.
fd
=
self
.
file
.
fileno
()
os
.
write
(
self
.
fd
,
bytes
(
maximum
-
minimum
))
def
close
(
self
):
self
.
file
.
close
(
)
os
.
close
(
self
.
fd
)
def
remove
(
self
):
os
.
remove
(
self
.
filename
)
...
...
@@ -31,6 +32,11 @@ class LockFile:
class
MailboxLock
(
Lock
):
"""
A simple lock that keeps a mailbox counter up-to-date
Used for a single process program to assure two asyncio tasks
do not use a mailbox at the same time, and keep the counter correct.
"""
def
__init__
(
self
):
super
().
__init__
()
self
.
counter
=
0
...
...
@@ -43,6 +49,11 @@ class MailboxLock(Lock):
class
ParallelMailboxLock
:
"""
A lock for the mailbox counter for multi-process programs
Write the mailbox counter to a :class:`LockFile`, such that different
processes can access the mailbox in order.
"""
def
__init__
(
self
,
lock_file
,
no
):
self
.
lock_file
=
lock_file
assert
self
.
lock_file
.
minimum
<=
no
<
self
.
lock_file
.
maximum
...
...
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