From 24a56c78b36d99eb3e11b178821478763386d9fc Mon Sep 17 00:00:00 2001 From: Ali Hamdi Ali Fadel Date: Fri, 25 Aug 2023 10:55:11 +0300 Subject: [PATCH] Remove sleep and use AsyncResult.wait instead of it --- tafrigh/recognizers/wit_recognizer.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tafrigh/recognizers/wit_recognizer.py b/tafrigh/recognizers/wit_recognizer.py index 74bec36..3c9b51a 100644 --- a/tafrigh/recognizers/wit_recognizer.py +++ b/tafrigh/recognizers/wit_recognizer.py @@ -86,10 +86,11 @@ def recognize( transcriptions = [] with tqdm(total=len(segments), disable=self.verbose is not False) as pbar: - while async_results: - if async_results[0].ready(): - transcriptions.append(async_results.pop(0).get()) - pbar.update(1) + for async_result in async_results: + async_result.wait() + pbar.update(1) + + transcriptions.append(async_result.get()) yield { 'progress': round(len(transcriptions) / len(segments) * 100, 2), @@ -98,8 +99,6 @@ def recognize( else None, } - time.sleep(0.1) - shutil.rmtree(temp_directory) return transcriptions