Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
seminar-breakout
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Shashank Suhas
seminar-breakout
Commits
99872a7b
Commit
99872a7b
authored
Jun 12, 2019
by
Yuxin Wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let MultiThreadRunner respect its len() (fix #1231)
parent
49fa0a07
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
tensorpack/dataflow/parallel.py
tensorpack/dataflow/parallel.py
+10
-2
No files found.
tensorpack/dataflow/parallel.py
View file @
99872a7b
...
@@ -416,7 +416,8 @@ class MultiThreadRunner(DataFlow):
...
@@ -416,7 +416,8 @@ class MultiThreadRunner(DataFlow):
Args:
Args:
get_df ( -> DataFlow): a callable which returns a DataFlow.
get_df ( -> DataFlow): a callable which returns a DataFlow.
Each thread will call this function to get the DataFlow to use.
Each thread will call this function to get the DataFlow to use.
Therefore do not return the same DataFlow for each call.
Therefore do not return the same DataFlow object for each call,
unless your dataflow is stateless.
num_prefetch (int): size of the queue
num_prefetch (int): size of the queue
num_thread (int): number of threads
num_thread (int): number of threads
nr_prefetch, nr_thread: deprecated names
nr_prefetch, nr_thread: deprecated names
...
@@ -438,6 +439,11 @@ class MultiThreadRunner(DataFlow):
...
@@ -438,6 +439,11 @@ class MultiThreadRunner(DataFlow):
MultiThreadRunner
.
_Worker
(
get_df
,
self
.
queue
)
MultiThreadRunner
.
_Worker
(
get_df
,
self
.
queue
)
for
_
in
range
(
num_thread
)]
for
_
in
range
(
num_thread
)]
try
:
self
.
_size
=
self
.
__len__
()
except
NotImplementedError
:
self
.
_size
=
-
1
def
reset_state
(
self
):
def
reset_state
(
self
):
for
th
in
self
.
threads
:
for
th
in
self
.
threads
:
th
.
df
.
reset_state
()
th
.
df
.
reset_state
()
...
@@ -447,7 +453,9 @@ class MultiThreadRunner(DataFlow):
...
@@ -447,7 +453,9 @@ class MultiThreadRunner(DataFlow):
return
self
.
threads
[
0
]
.
df
.
__len__
()
return
self
.
threads
[
0
]
.
df
.
__len__
()
def
__iter__
(
self
):
def
__iter__
(
self
):
while
True
:
for
k
in
itertools
.
count
():
if
self
.
_size
>
0
and
k
>=
self
.
_size
:
break
yield
self
.
queue
.
get
()
yield
self
.
queue
.
get
()
def
__del__
(
self
):
def
__del__
(
self
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment