'"An attempt has been made to start a new process before the current process has finished its bootstrapping phase." error trying to get stat-cast data
I am currently working on a baseball simulation project that I created in Google Colab but am trying to move over into PyCharm so I can have more control over saving the models and cleaning up my files. I have tried to run the following code on PyCharm:
import pybaseball
from pybaseball import statcast_batter, statcast, playerid_lookup
pybaseball.cache.enable()
data = statcast("2021-04-01", "2022-12-01")
and get the following error:
This is a large query, it may take a moment to complete
Skipping offseason dates
Skipping offseason dates
0%| | 0/475 [00:00<?, ?it/s]
This is a large query, it may take a moment to complete
Skipping offseason dates
This is a large query, it may take a moment to complete
Skipping offseason dates
Skipping offseason dates
Skipping offseason dates
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/spawn.py", line 125, in _main
prepare(preparation_data)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/spawn.py", line 236, in prepare
0%| | 0/475 [00:00<?, ?it/s] _fixup_main_from_path(data['init_main_from_path'])
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 269, in run_path
return _run_module_code(code, init_globals, run_name,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 96, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/Users/dmeredith/PycharmProjects/ML(B)/MLB.py", line 19, in <module>
data = statcast("2021-04-01", "2022-12-01")
File "/Users/dmeredith/PycharmProjects/ML(B)/venv/lib/python3.10/site-packages/pybaseball/statcast.py", line 110, in statcast
return _handle_request(start_dt_date, end_dt_date, 1, verbose=verbose,
File "/Users/dmeredith/PycharmProjects/ML(B)/venv/lib/python3.10/site-packages/pybaseball/statcast.py", line 70, in _handle_request
futures = {executor.submit(_small_request, subq_start, subq_end, team=team)
File "/Users/dmeredith/PycharmProjects/ML(B)/venv/lib/python3.10/site-packages/pybaseball/statcast.py", line 70, in <setcomp>
futures = {executor.submit(_small_request, subq_start, subq_end, team=team)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/concurrent/futures/process.py", line 705, in submit
0%| | 0/475 [00:00<?, ?it/s]
Traceback (most recent call last):
File "<string>", line 1, in <module>
self._adjust_process_count()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/concurrent/futures/process.py", line 683, in _adjust_process_count
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/spawn.py", line 125, in _main
p.start()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/process.py", line 121, in start
prepare(preparation_data)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/spawn.py", line 236, in prepare
self._popen = self._Popen(self)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/context.py", line 284, in _Popen
_fixup_main_from_path(data['init_main_from_path'])
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
return Popen(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 32, in __init__
main_content = runpy.run_path(main_path,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 269, in run_path
super().__init__(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/popen_fork.py", line 19, in __init__
return _run_module_code(code, init_globals, run_name,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 96, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
self._launch(process_obj)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 42, in _launch
exec(code, run_globals)
File "/Users/dmeredith/PycharmProjects/ML(B)/MLB.py", line 19, in <module>
prep_data = spawn.get_preparation_data(process_obj._name)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/spawn.py", line 154, in get_preparation_data
data = statcast("2021-04-01", "2022-12-01")
File "/Users/dmeredith/PycharmProjects/ML(B)/venv/lib/python3.10/site-packages/pybaseball/statcast.py", line 110, in statcast
return _handle_request(start_dt_date, end_dt_date, 1, verbose=verbose,
File "/Users/dmeredith/PycharmProjects/ML(B)/venv/lib/python3.10/site-packages/pybaseball/statcast.py", line 70, in _handle_request
_check_not_importing_main()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/spawn.py", line 134, in _check_not_importing_main
futures = {executor.submit(_small_request, subq_start, subq_end, team=team)
File "/Users/dmeredith/PycharmProjects/ML(B)/venv/lib/python3.10/site-packages/pybaseball/statcast.py", line 70, in <setcomp>
futures = {executor.submit(_small_request, subq_start, subq_end, team=team)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/concurrent/futures/process.py", line 705, in submit
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.
self._adjust_process_count()
It has worked fine in Google Colab but now it is not working in PyCharm. I am using python 3.10 but may have set up the virtual environment or project wrong as I don't have much experience in PyCharm.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
