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
bb213f4d
Commit
bb213f4d
authored
4 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
add exception
parent
699b3fed
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/futures/collection.py
+28
-2
28 additions, 2 deletions
satella/coding/concurrent/futures/collection.py
tests/test_coding/test_concurrent.py
+7
-0
7 additions, 0 deletions
tests/test_coding/test_concurrent.py
with
35 additions
and
2 deletions
satella/coding/concurrent/futures/collection.py
+
28
−
2
View file @
bb213f4d
import
concurrent
import
typing
as
tp
from
concurrent.futures
import
Future
...
...
@@ -109,9 +110,34 @@ class FutureCollection:
:param timeout: a timeout in seconds for a single result. Default value None means
wait as long as necessary
:return: list containing results of all futures
:raises
TimeoutErr
or: timeout while waiting for result
:raises
WouldWaitM
or
e
: timeout while waiting for result
"""
return
[
fut
.
result
(
timeout
)
for
fut
in
self
.
futures
]
try
:
return
[
fut
.
result
(
timeout
)
for
fut
in
self
.
futures
]
except
concurrent
.
futures
.
TimeoutError
:
raise
WouldWaitMore
(
'
timeout waiting for the result
'
)
def
exception
(
self
,
timeout
:
tp
.
Optional
[
float
]
=
None
)
->
tp
.
Optional
[
Exception
]:
"""
Return first exception raised by any of the futures
This will block until the results are available.
This call proceeding does not mean that results for all are available, since
this will return the first exception encountered!
:param timeout: a timeout in seconds for a single result. Default value None means
wait as long as necessary
:return: the first exception, or None if there were no exceptions
:raises WouldWaitMore: timeout while waiting for result
"""
try
:
for
fut
in
self
.
futures
:
e
=
fut
.
exception
(
timeout
)
if
e
is
not
None
:
return
e
return
None
except
concurrent
.
futures
.
TimeoutError
:
raise
WouldWaitMore
(
'
timeout waiting for the result
'
)
def
cancel
(
self
)
->
bool
:
"""
...
...
This diff is collapsed.
Click to expand it.
tests/test_coding/test_concurrent.py
+
7
−
0
View file @
bb213f4d
...
...
@@ -19,6 +19,13 @@ from satella.exceptions import WouldWaitMore, AlreadyAllocated, Empty
class
TestConcurrent
(
unittest
.
TestCase
):
def
test_future_collection_exception
(
self
):
fc
=
FutureCollection
([
PythonFuture
(),
PythonFuture
()])
fc
.
set_running_or_notify_cancel
()
fc
[
0
].
set_exception
(
IndexError
())
fc
[
1
].
set_exception
(
ValueError
())
self
.
assertIsInstance
(
fc
.
exception
(),
IndexError
)
def
test_future_collection_callbacks_one
(
self
):
a
=
{
'
count
'
:
0
}
...
...
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