Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The dl_files function is giving an error #306

Open
briangow opened this issue Jun 15, 2021 · 4 comments
Open

The dl_files function is giving an error #306

briangow opened this issue Jun 15, 2021 · 4 comments

Comments

@briangow
Copy link
Contributor

The wfdb.io.dl_files function is working in older version of python (v3.6) but is failing with the following error in a newer version (3.9.5):

Downloading files...
Traceback (most recent call last):
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/spawn.py", line 125, in _main
    prepare(preparation_data)
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/runpy.py", line 268, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/temp_credentialed_download.py", line 5, in <module>
    wfdb.io.dl_files('mitdb','/Users/briangow/Documents/MIT/physionet/files',['115.dat'])
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/site-packages/wfdb/io/download.py", line 531, in dl_files
    pool = multiprocessing.Pool(processes=2)
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/context.py", line 119, in Pool
    return Pool(processes, initializer, initargs, maxtasksperchild,
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/pool.py", line 212, in __init__
    self._repopulate_pool()
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/pool.py", line 303, in _repopulate_pool
    return self._repopulate_pool_static(self._ctx, self.Process,
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/pool.py", line 326, in _repopulate_pool_static
    w.start()
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 42, in _launch
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/multiprocessing/spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "/Users/briangow/Documents/MIT/physionet/physionet-build/env/lib/python3.9/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.
python-BaseException
@bemoody
Copy link
Collaborator

bemoody commented Oct 1, 2021

Looks like multiprocessing shenanigans; see also pull #330.

Same question here - does changing multiprocessing.Pool to multiprocessing.dummy.Pool fix the issue?

@cx1111
Copy link
Member

cx1111 commented Mar 31, 2022

@briangow are you on a Mac?

According to https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods: "Changed in version 3.8: On macOS, the spawn start method is now the default. "

Just wanted to confirm that along with the user from #330, that the spawn start method is causing the issue.

@briangow
Copy link
Contributor Author

@cx1111 , I am on a Mac. The issue appears to be related to not using if __name__ == '__main__':. If I start my script without using that I get the error posted above in recent versions of python (3.10.dev in this case) but it works without it in an older version (3.6).

This issue suggests what Windows users need to start from within if __name__ == '__main__': for multiprocessing but it appears that I do on a Mac also: https://stackoverflow.com/questions/24374288/where-to-put-freeze-support-in-a-python-script .

@cx1111
Copy link
Member

cx1111 commented Apr 25, 2022

Let's keep this open until we can either make the library more robust to this behavior, or at least publicly document a workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants