Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
group-connectivity-pub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Radek Hušek
group-connectivity-pub
Commits
c6046692
Commit
c6046692
authored
9 years ago
by
Radek Hušek
Committed by
Radek Hušek
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
parmap: simplify generator termination
parent
b8f62c17
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
parmap.py
+11
-14
11 additions, 14 deletions
parmap.py
with
11 additions
and
14 deletions
parmap.py
+
11
−
14
View file @
c6046692
...
...
@@ -14,22 +14,19 @@ def chunkme(X, chunksize):
if
len
(
chunk
):
yield
chunk
def
producer_fun
(
X
,
q_in
,
q_out
,
cont
,
nprocs
,
chunksize
):
sent
=
0
def
producer_fun
(
X
,
q_in
,
cont
,
nprocs
,
chunksize
):
for
i
,
x
in
enumerate
(
chunkme
(
X
,
chunksize
)):
cont
.
acquire
()
q_in
.
put
((
i
,
x
))
sent
+=
1
for
_
in
range
(
nprocs
):
q_in
.
put
((
None
,
None
))
q_out
.
put
((
None
,
sent
))
def
worker_fun
(
f
,
q_in
,
q_out
):
while
True
:
i
,
chunk
=
q_in
.
get
()
if
i
is
None
:
q_out
.
put
((
None
,
None
))
break
q_out
.
put
((
i
,
[
f
(
x
)
for
x
in
chunk
]))
...
...
@@ -53,7 +50,7 @@ def parmap(f, X, nprocs = None, chunksize = 1, chunks_in_flight = None,
proc
.
append
(
multiprocessing
.
Process
(
target
=
producer_fun
,
args
=
(
X
,
q_in
,
q_out
,
cont
,
nprocs
,
chunksize
)
args
=
(
X
,
q_in
,
cont
,
nprocs
,
chunksize
)
))
for
p
in
proc
:
...
...
@@ -63,12 +60,12 @@ def parmap(f, X, nprocs = None, chunksize = 1, chunks_in_flight = None,
def
get_chunk
():
ret
=
{}
chunk_index
=
0
jobs
=
None
running_workers
=
nprocs
while
jobs
is
None
or
chunk_index
<
jobs
:
while
running_workers
>
0
:
i
,
val
=
q_out
.
get
()
if
i
is
None
:
job
s
=
val
running_worker
s
-
=
1
continue
if
not
inOrder
:
...
...
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