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
c9a92380
Commit
c9a92380
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
more coverage + add timeout to join
parent
6b5e42ec
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+1
-0
1 addition, 0 deletions
CHANGELOG.md
satella/coding/concurrent/thread_collection.py
+11
-2
11 additions, 2 deletions
satella/coding/concurrent/thread_collection.py
tests/test_coding/test_concurrent.py
+6
-2
6 additions, 2 deletions
tests/test_coding/test_concurrent.py
with
18 additions
and
4 deletions
CHANGELOG.md
+
1
−
0
View file @
c9a92380
...
...
@@ -2,3 +2,4 @@
*
added
`MetricDataCollection.remove_internals`
*
added
`whereis`
*
added
`timeout`
to
`ThreadCollection.join`
This diff is collapsed.
Click to expand it.
satella/coding/concurrent/thread_collection.py
+
11
−
2
View file @
c9a92380
...
...
@@ -2,6 +2,8 @@ import threading
import
typing
as
tp
from
threading
import
Thread
from
satella.exceptions
import
WouldWaitMore
class
ThreadCollection
:
"""
...
...
@@ -116,14 +118,21 @@ class ThreadCollection:
pass
return
self
def
join
(
self
)
->
'
ThreadCollection
'
:
def
join
(
self
,
timeout
:
tp
.
Optional
[
float
]
=
None
)
->
'
ThreadCollection
'
:
"""
Join all threads
:param timeout: maximum time in seconds to wait for the threads to terminate.
Note that the timeout will be applied to each thread in sequence, so this
can block for up to thread_count*timeout seconds. Default value of
None means wait as long as it
'
s necessary.
:returns: this thread collection instance
:raises WouldWaitMore: one of the threads failed to terminate
"""
for
thread
in
self
.
threads
:
thread
.
join
()
thread
.
join
(
timeout
=
timeout
)
if
thread
.
is_alive
():
raise
WouldWaitMore
(
'
Thread failed to terminate
'
)
return
self
def
is_alive
(
self
)
->
bool
:
...
...
This diff is collapsed.
Click to expand it.
tests/test_coding/test_concurrent.py
+
6
−
2
View file @
c9a92380
...
...
@@ -29,17 +29,21 @@ class TestConcurrent(unittest.TestCase):
def
run
(
self
):
nonlocal
dct
dct
[
self
.
a
]
=
True
if
self
.
a
==
6
:
time
.
sleep
(
5
)
self
.
assertGreaterEqual
(
len
(
ThreadCollection
.
get_currently_running
()),
1
)
tc
=
ThreadCollection
.
from_class
(
Threading
,
[
2
,
3
,
4
])
tc
.
daemon
=
False
self
.
assertFalse
(
tc
.
is_alive
())
self
.
assertEqual
(
len
(
tc
),
3
)
self
.
assertFalse
(
tc
.
daemon
)
self
.
assertEqual
(
len
(
tc
.
get_currently_running
()),
0
)
for
t
in
tc
:
self
.
assertIsInstance
(
t
,
Threading
)
tc
.
append
(
Threading
(
5
)).
add
(
Threading
(
6
))
tc
.
start
().
terminate
().
join
()
tc
.
start
()
self
.
assertRaises
(
WouldWaitMore
,
lambda
:
tc
.
join
(
2
))
tc
.
terminate
().
join
()
self
.
assertEqual
(
dct
,
{
2
:
True
,
3
:
True
,
4
:
True
,
5
:
True
,
6
:
True
})
def
test_cancellable_callback
(
self
):
...
...
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