From 60a8f66ffd6379168c0b2b4217a6a31874d2134b Mon Sep 17 00:00:00 2001 From: "Raryel C. Souza" Date: Tue, 12 Feb 2019 00:39:29 +0700 Subject: [PATCH 1/5] Fix crash macos because of multiprocessing. --- autosub/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/autosub/__init__.py b/autosub/__init__.py index 61019464..27443004 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -233,6 +233,11 @@ def generate_subtitles( # pylint: disable=too-many-locals,too-many-arguments """ Given an input audio/video file, generate subtitles in the specified language and format. """ + if "Darwin" in os.uname(): + #the default unix fork method does not work on Mac OS + #need to use forkserver + multiprocessing.set_start_method('forkserver') + audio_filename, audio_rate = extract_audio(source_path) regions = find_speech_regions(audio_filename) From 54114a2412c37acf6949358f9d6088a84951e36d Mon Sep 17 00:00:00 2001 From: "Raryel C. Souza" Date: Tue, 12 Feb 2019 10:49:53 +0700 Subject: [PATCH 2/5] Added try catch to avoid crash on python 2. --- autosub/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/autosub/__init__.py b/autosub/__init__.py index 27443004..70f7651c 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -236,7 +236,11 @@ def generate_subtitles( # pylint: disable=too-many-locals,too-many-arguments if "Darwin" in os.uname(): #the default unix fork method does not work on Mac OS #need to use forkserver - multiprocessing.set_start_method('forkserver') + try: + multiprocessing.set_start_method('forkserver') + except AttributeError: + # for python 2 not have set_start_method... cannot be used on mac + print("Python 2 fork() does not work on MacOS. Please use Python 3 instead.") audio_filename, audio_rate = extract_audio(source_path) From 7061734ac2fc708d75b357ee4f018e8a344c845b Mon Sep 17 00:00:00 2001 From: "Raryel C. Souza" Date: Tue, 12 Feb 2019 11:08:53 +0700 Subject: [PATCH 3/5] Guarantee that set_start_method will only execute once. (otherwise would crash acccording to documentation). --- autosub/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autosub/__init__.py b/autosub/__init__.py index 70f7651c..38cdcc02 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -237,7 +237,8 @@ def generate_subtitles( # pylint: disable=too-many-locals,too-many-arguments #the default unix fork method does not work on Mac OS #need to use forkserver try: - multiprocessing.set_start_method('forkserver') + if 'forkserver' not in multiprocessing.get_start_method(): + multiprocessing.set_start_method('forkserver') except AttributeError: # for python 2 not have set_start_method... cannot be used on mac print("Python 2 fork() does not work on MacOS. Please use Python 3 instead.") From a73bccaa08da9afe4b623a099d39d1449d1b985a Mon Sep 17 00:00:00 2001 From: "Raryel C. Souza" Date: Tue, 12 Feb 2019 13:07:14 +0700 Subject: [PATCH 4/5] Parameter allow_none=True added, otherwise would manually set to default. --- autosub/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autosub/__init__.py b/autosub/__init__.py index 38cdcc02..eb2063e1 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -237,7 +237,7 @@ def generate_subtitles( # pylint: disable=too-many-locals,too-many-arguments #the default unix fork method does not work on Mac OS #need to use forkserver try: - if 'forkserver' not in multiprocessing.get_start_method(): + if 'forkserver' not in multiprocessing.get_start_method(allow_none=True): multiprocessing.set_start_method('forkserver') except AttributeError: # for python 2 not have set_start_method... cannot be used on mac From d838c9b5f918bd9d9e188c6ccba6625b3a6276e9 Mon Sep 17 00:00:00 2001 From: "Raryel C. Souza" Date: Tue, 12 Feb 2019 13:53:52 +0700 Subject: [PATCH 5/5] for compatibility with Windows --- autosub/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autosub/__init__.py b/autosub/__init__.py index eb2063e1..a6c560ab 100644 --- a/autosub/__init__.py +++ b/autosub/__init__.py @@ -233,7 +233,7 @@ def generate_subtitles( # pylint: disable=too-many-locals,too-many-arguments """ Given an input audio/video file, generate subtitles in the specified language and format. """ - if "Darwin" in os.uname(): + if os.name != "nt" and "Darwin" in os.uname(): #the default unix fork method does not work on Mac OS #need to use forkserver try: