Skip to content

Commit

Permalink
Merge pull request #446 from pkuyym/fix-445
Browse files Browse the repository at this point in the history
Add clean callback.
  • Loading branch information
pkuyym committed Nov 10, 2017
2 parents 474a0ae + 70511e9 commit 060480f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion deep_speech_2/data_utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import numpy as np
import paddle.v2 as paddle
from threading import local
import atexit
from data_utils.utility import read_manifest
from data_utils.utility import xmap_readers_mp
from data_utils.augmentor.augmentation import AugmentationPipeline
Expand Down Expand Up @@ -274,13 +275,18 @@ def reader():
for instance in manifest:
yield instance

return xmap_readers_mp(
reader, cleanup_callback = xmap_readers_mp(
lambda instance: self.process_utterance(instance["audio_filepath"], instance["text"]),
reader,
self._num_threads,
4096,
order=True)

# register callback to main process
atexit.register(cleanup_callback)

return reader

def _padding_batch(self, batch, padding_to=-1, flatten=False):
"""
Padding audio features with zeros to make them have the same shape (or
Expand Down
6 changes: 5 additions & 1 deletion deep_speech_2/data_utils/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ def flush_worker(in_queue, out_queue):
out_queue.put(sample)
out_queue.put(end_flag)

def cleanup():
# kill all sub process and threads
os._exit(0)

def xreader():
# prepare shared memory
manager = Manager()
Expand Down Expand Up @@ -174,4 +178,4 @@ def xreader():
yield sample
sample = flush_queue.get()

return xreader
return xreader, cleanup

0 comments on commit 060480f

Please sign in to comment.