Skip to content

Commit

Permalink
openage.util.threading: fixed concurrent_chain
Browse files Browse the repository at this point in the history
used to fail when given zero generators
  • Loading branch information
mic-e committed Jul 29, 2015
1 parent 23ea234 commit 5bdce38
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions openage/convert/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,6 @@ def convert_metadata(args):

def convert_media(args):
""" Converts the media part """
info("converting media")

ignored_suffixes = set()
if args.flag("no_sounds"):
ignored_suffixes.add('.wav')
Expand All @@ -177,6 +175,11 @@ def convert_media(args):

yield len(files_to_convert)

if not files_to_convert:
return

info("converting media")

jobs = getattr(args, "jobs", None)
with SLPConverterPool(args.palette, jobs) as slp_converter:
args.slp_converter = slp_converter
Expand Down
6 changes: 3 additions & 3 deletions openage/util/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def concurrent_chain(generators, jobs=None):
pool.submit(generator_to_queue, generator, queue)
running_generator_count += 1

while True:
while running_generator_count > 0:
event_type, value = queue.get()

if event_type == GeneratorEvent.VALUE:
Expand All @@ -48,8 +48,6 @@ def concurrent_chain(generators, jobs=None):
raise value
elif event_type == GeneratorEvent.STOP_ITERATION:
running_generator_count -= 1
if running_generator_count == 0:
return


class ClosableQueue(Queue):
Expand Down Expand Up @@ -122,6 +120,8 @@ def errorgen():
yield "errorgen"
raise ValueError()

assert_value(list(concurrent_chain([], 2)), [])

assert_value(list(concurrent_chain([range(10)], 2)), list(range(10)))

assert_value(
Expand Down

0 comments on commit 5bdce38

Please sign in to comment.