Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
abb_egm_pyclient
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
Container 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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Robotlab
abb_egm_pyclient
Commits
3e782aea
Commit
3e782aea
authored
3 years ago
by
Anton Tetov Johansson
Browse files
Options
Downloads
Patches
Plain Diff
tooling
parent
761ab035
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
abb_egm_client/atomic_counter.py
+60
-0
60 additions, 0 deletions
abb_egm_client/atomic_counter.py
environment.yml
+2
-1
2 additions, 1 deletion
environment.yml
pyproject.toml
+3
-0
3 additions, 0 deletions
pyproject.toml
setup.cfg
+11
-1
11 additions, 1 deletion
setup.cfg
with
76 additions
and
2 deletions
abb_egm_client/atomic_counter.py
0 → 100644
+
60
−
0
View file @
3e782aea
import
threading
class
AtomicCounter
:
"""
An atomic, thread-safe counter.
From:
https://gist.github.com/benhoyt/8c8a8d62debe8e5aa5340373f9c509c7#gistcomment-3142969
>>>
counter
=
AtomicCounter
()
>>>
counter
.
inc
()
1
>>>
counter
.
inc
(
num
=
4
)
5
>>>
counter
=
AtomicCounter
(
42.5
)
>>>
counter
.
value
42.5
>>>
counter
.
inc
(
num
=
0.5
)
43.0
>>>
counter
=
AtomicCounter
()
>>>
def
incrementor
():
...
for
i
in
range
(
100000
):
...
counter
.
inc
()
>>>
threads
=
[]
>>>
for
i
in
range
(
4
):
...
thread
=
threading
.
Thread
(
target
=
incrementor
)
...
thread
.
start
()
...
threads
.
append
(
thread
)
>>>
for
thread
in
threads
:
...
thread
.
join
()
>>>
counter
.
value
400000
"""
def
__init__
(
self
,
initial
=
0
):
"""
Initialize a new atomic counter to given initial value
"""
self
.
_value
=
initial
self
.
_lock
=
threading
.
Lock
()
def
inc
(
self
,
num
=
1
):
"""
Atomically increment the counter by num and return the new value
"""
with
self
.
_lock
:
self
.
_value
+=
num
return
self
.
_value
def
dec
(
self
,
num
=
1
):
"""
Atomically decrement the counter by num and return the new value
"""
with
self
.
_lock
:
self
.
_value
-=
num
return
self
.
_value
@property
def
value
(
self
):
return
self
.
_value
if
__name__
==
"
__main__
"
:
import
doctest
doctest
.
testmod
()
This diff is collapsed.
Click to expand it.
environment.yml
+
2
−
1
View file @
3e782aea
name
:
abb-egm-examples
name
:
abb-egm-examples
1
channels
:
-
conda-forge
dependencies
:
-
python >=3.9, <3.10
-
numpy
-
protobuf
This diff is collapsed.
Click to expand it.
pyproject.toml
+
3
−
0
View file @
3e782aea
...
...
@@ -4,3 +4,6 @@ requires = [
"wheel"
,
]
build-backend
=
"setuptools.build_meta"
[tool.isort]
profile
=
"black"
This diff is collapsed.
Click to expand it.
setup.cfg
+
11
−
1
View file @
3e782aea
...
...
@@ -4,6 +4,16 @@ version = 0.1.0
[options]
packages
=
abb_egm_client
python_requires
=
>= 3.
8
python_requires
=
>= 3.
9
install_requires
=
protobuf
[options.extras_require]
dev
=
black
flake8
isort
>=
5.0.0
[flake8]
max-line-length
=
88
extend-ignore
=
E203
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