PolyglotDB icon indicating copy to clipboard operation
PolyglotDB copied to clipboard

Multiprocessing-related error running from command line

Open msonderegger opened this issue 3 years ago • 2 comments

System info:

Screen Shot 2022-04-20 at 10 44 06 AM

I am trying to run a slightly modified version of this script, on the command line, with

python tutorial_formants.py

(I'm running this on a tiny subset of the tutorial LibriSpeech corpus.)

I have polyglot installed in a conda environment. The script works when I run it from inside the Python interpreter, with exec, or if I run it on the command line with

c.analyze_formant_points(vowel_label='vowel', call_back=print)

changed to

c.analyze_formant_points(vowel_label='vowel', call_back=print, multiprocessing=False)

But when I run from the command line, I get this error:

...
3
Importing data for speaker 0 of 2 (5105)...
Importing data for speaker 1 of 2 (5639)...
['<SIL>', 'AA0', 'AA1', 'AE0', 'AE1', 'AH0', 'AH1', 'AO1', 'AO2', 'AW1', 'AY1', 'AY2', 'B', 'CH', 'D', 'DH', 'EH1', 'EH2', 'ER0', 'ER1', 'EY1', 'EY2', 'F', 'G', 'HH', 'IH0', 'IH1', 'IH2', 'IY0', 'IY1', 'JH', 'K', 'L', 'M', 'N', 'NG', 'OW0', 'OW1', 'OW2', 'OY1', 'P', 'R', 'S', 'SH', 'T', 'TH', 'UH1', 'UW1', 'V', 'W', 'Y', 'Z', 'sil', 'spn']
vowels:  ['AA0', 'AA1', 'AE0', 'AE1', 'AH0', 'AH1', 'AO1', 'AO2', 'AW1', 'AY1', 'AY2', 'EH1', 'EH2', 'ER0', 'ER1', 'EY1', 'EY2', 'IH0', 'IH1', 'IH2', 'IY0', 'IY1', 'OW0', 'OW1', 'OW2', 'OY1', 'UH1', 'UW1']
Encoding vowel set...
Encoding vowel syllables...
Speaker enrichment begun...
Speaking rate...
Formant calculations...
Analyzing files...
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/spawn.py", line 125, in _main
    prepare(preparation_data)
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/runpy.py", line 269, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/morgan/PolyglotDB-repo/examples/tutorial_formants.py", line 89, in <module>
    c.analyze_formant_points(vowel_label='vowel', call_back=print)
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/site-packages/polyglotdb-1.2.1-py3.10.egg/polyglotdb/corpus/audio.py", line 395, in analyze_formant_points
    data = analyze_formant_points(self,  stop_check=stop_check, call_back=call_back,
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/site-packages/polyglotdb-1.2.1-py3.10.egg/polyglotdb/acoustics/formants/base.py", line 46, in analyze_formant_points
    output = analyze_segments(segment_mapping, formant_function,
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/site-packages/conch/main.py", line 199, in analyze_segments
    output_dict = generate_cache_mp(segment_mapping, analysis_function, num_cores,
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/site-packages/conch/multiprocessing.py", line 161, in generate_cache
    manager = Manager()
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/context.py", line 57, in Manager
    m.start()
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/managers.py", line 562, in start
    self._process.start()
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 42, in _launch
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.
Traceback (most recent call last):
  File "/Users/morgan/PolyglotDB-repo/examples/tutorial_formants.py", line 89, in <module>
    c.analyze_formant_points(vowel_label='vowel', call_back=print)
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/site-packages/polyglotdb-1.2.1-py3.10.egg/polyglotdb/corpus/audio.py", line 395, in analyze_formant_points
    data = analyze_formant_points(self,  stop_check=stop_check, call_back=call_back,
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/site-packages/polyglotdb-1.2.1-py3.10.egg/polyglotdb/acoustics/formants/base.py", line 46, in analyze_formant_points
    output = analyze_segments(segment_mapping, formant_function,
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/site-packages/conch/main.py", line 199, in analyze_segments
    output_dict = generate_cache_mp(segment_mapping, analysis_function, num_cores,
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/site-packages/conch/multiprocessing.py", line 161, in generate_cache
    manager = Manager()
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/context.py", line 57, in Manager
    m.start()
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/managers.py", line 566, in start
    self._address = reader.recv()
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/connection.py", line 255, in recv
    buf = self._recv_bytes()
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/connection.py", line 419, in _recv_bytes
    buf = self._recv(4)
  File "/Users/morgan/opt/anaconda3/envs/polyglotdb-dev/lib/python3.10/multiprocessing/connection.py", line 388, in _recv
    raise EOFError
EOFError

I think it has something to do with multiprocessing when called from __main__, but not sure...

Thanks!

msonderegger avatar Apr 20 '22 14:04 msonderegger

I haven't run into this issue myself, but it would be strange for this to be system dependent.

I can see that the function throwing this error comes from our conch library: https://github.com/mmcauliffe/Conch-sounds/blob/e05535fd08e4b0e47e37a77ef521d05eff1d6bc5/conch/main.py#L191

Indeed we are using this function directly without wrapping it in a __main__ block -- I'm not an expert in multithreading in python, but it seems the error is implying you need a main environment in order to bootstrap new subprocesses. However, I just ran this code on my system (Ubuntu 20.04, conda environment) without issue. I'll see if I can reproduce somehow.

michaelhaaf avatar Apr 20 '22 18:04 michaelhaaf

@mmcauliffe had a suggestion about this on Slack -- what was it again?

msonderegger avatar Jun 30 '22 20:06 msonderegger