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
84e61fb1
Commit
84e61fb1
authored
3 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
close the scope upon creation
parent
629843de
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
satella/coding/concurrent/list_processor.py
+5
-6
5 additions, 6 deletions
satella/coding/concurrent/list_processor.py
with
5 additions
and
6 deletions
satella/coding/concurrent/list_processor.py
+
5
−
6
View file @
84e61fb1
...
...
@@ -11,7 +11,8 @@ except ImportError:
def
parallel_construct
(
iterable
:
tp
.
Iterable
[
V
],
function
:
tp
.
Callable
[[
V
],
tp
.
Optional
[
U
]],
thread_pool
:
ThreadPoolExecutor
)
->
tp
.
List
[
U
]:
thread_pool
:
ThreadPoolExecutor
,
span_title
:
tp
.
Optional
[
str
]
=
None
)
->
tp
.
List
[
U
]:
"""
Construct a list from executing given function in a thread pool executor.
...
...
@@ -20,6 +21,7 @@ def parallel_construct(iterable: tp.Iterable[V],
:param iterable: iterable to apply
:param function: function to apply. If that function returns None, no element will be added
:param thread_pool: thread pool to execute
:param span_title: span title to create. For each execution a child span will be returned
:return: list that is the result of parallel application of function on each element
"""
wrap_iterable
=
None
...
...
@@ -28,13 +30,10 @@ def parallel_construct(iterable: tp.Iterable[V],
tracer
=
opentracing
.
global_tracer
()
span
=
tracer
.
active_span
if
span
is
not
None
:
current_span
=
tracer
.
active_span
def
wrap_iterable
(
arg
,
*
args
,
**
kwargs
):
scope
=
tracer
.
scope_manager
.
activate
(
current_span
,
finish_on_close
=
False
)
v
=
function
(
arg
,
*
args
,
**
kwargs
)
scope
.
close
()
return
v
with
tracer
.
start_active_span
(
span_title
or
'
New span
'
,
child_of
=
span
):
return
function
(
arg
,
*
args
,
**
kwargs
)
if
wrap_iterable
is
None
:
wrap_iterable
=
function
...
...
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