Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
1b20d3bf
Commit
1b20d3bf
authored
1 year ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
fix docs
Change-Id: Ib40568bd0795538a20de855873d8c49f53bb9068
parent
903df7dc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
satella/coding/concurrent/timer.py
+3
-4
3 additions, 4 deletions
satella/coding/concurrent/timer.py
satella/coding/concurrent/value.py
+5
-8
5 additions, 8 deletions
satella/coding/concurrent/value.py
with
8 additions
and
12 deletions
satella/coding/concurrent/timer.py
+
3
−
4
View file @
1b20d3bf
...
...
@@ -20,17 +20,16 @@ class Timer:
There might be up to a second of delay before the timer is picked up.
If spawn_separate is False, exceptions will be logged
n
If spawn_separate is False, exceptions will be logged
.
:param interval: amount of seconds that should elapse
d
between calling start() and function
:param interval: amount of seconds that should elapse between calling start() and function
executing. Can be also a time string.
:param function: function to execute
:param args: argument for function
:param kwargs: kwargs for function
:param spawn_separate: whether to call the function in a separate thread
"""
__slots__
=
(
'
args
'
,
'
kwargs
'
,
'
spawn_separate
'
,
'
interval
'
,
'
function
'
,
'
execute_at
'
,
'
cancelled
'
)
__slots__
=
'
args
'
,
'
kwargs
'
,
'
spawn_separate
'
,
'
interval
'
,
'
function
'
,
'
execute_at
'
,
'
cancelled
'
def
__init__
(
self
,
interval
:
tp
.
Union
[
str
,
float
],
function
,
args
=
None
,
kwargs
=
None
,
spawn_separate
=
False
):
...
...
This diff is collapsed.
Click to expand it.
satella/coding/concurrent/value.py
+
5
−
8
View file @
1b20d3bf
...
...
@@ -2,14 +2,11 @@ import time
import
typing
as
tp
from
threading
import
Event
from
satella.coding.misc
import
_BLANK
from
satella.coding.typing
import
T
from
satella.exceptions
import
WouldWaitMore
class
_UNSET
:
pass
class
DeferredValue
(
tp
.
Generic
[
T
]):
"""
A class that allows you to pass arguments that will be available later during runtime.
...
...
@@ -29,7 +26,7 @@ class DeferredValue(tp.Generic[T]):
def
__init__
(
self
):
self
.
lock
=
Event
()
self
.
val
=
_
UNSET
self
.
val
=
_
BLANK
def
set_value
(
self
,
va
:
T
)
->
None
:
"""
...
...
@@ -38,7 +35,7 @@ class DeferredValue(tp.Generic[T]):
:param va: value to set
:raises ValueError: value is already set
"""
if
self
.
val
is
not
_
UNSET
:
if
self
.
val
is
not
_
BLANK
:
raise
ValueError
(
'
Value curently set!
'
)
self
.
val
=
va
self
.
lock
.
set
()
...
...
@@ -49,13 +46,13 @@ class DeferredValue(tp.Generic[T]):
def
value
(
self
,
timeout
:
tp
.
Optional
[
float
]
=
None
)
->
T
:
"""
Wait until value is available.
Wait until value is available
, and return it
.
:param timeout: number of seconds to wait. If None is given, this will take as long as necessary.
:return: a value
:raises WouldWaitMore: timeout was given and it has expired
"""
if
self
.
val
is
not
_
UNSET
:
if
self
.
val
is
not
_
BLANK
:
return
self
.
val
tout
=
self
.
lock
.
wait
(
timeout
)
if
not
tout
:
...
...
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