Multiprocessing ProcessPoolExecutor - BrokenProcessPool Error when run in Windows command line - python

I am using executor.map and storing results in 'results'.
Following code works without any problem on Jupiter notebook. However, it crashes when executing the python script in Windows command prompt.
rop_test.py
print ('start of process')
import concurrent.futures
from funcfile import func
if __name__ == '__main__':
with concurrent.futures.ProcessPoolExecutor() as executor:
results = executor.map(func, varlist1,varlist2)
global master_list
master_list=list(results)
print(master_list)
#do something with master_list
funcfile.py
def func(var1,var2):
var3=var1+var2
return var3
Error
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 225, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
run_name="__mp_main__")
File "C:\ProgramData\Anaconda3\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\ProgramData\Anaconda3\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\ProgramData\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Administrator\notebooks\rop_test.py", line 640, in <module>
print (master_list)
NameError: name 'master_list' is not defined
Finished in 0.0 second(s)
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 225, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\ProgramData\Anaconda3\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
run_name="__mp_main__")
File "C:\ProgramData\Anaconda3\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\ProgramData\Anaconda3\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\ProgramData\Anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Administrator\notebooks\rop_test.py", line 640, in <module>
print (master_list)
NameError: name 'master_list' is not defined
Traceback (most recent call last):
File "rop_test.py", line 634, in <module>
master_list=list(results)
File "C:\ProgramData\Anaconda3\lib\concurrent\futures\process.py", line 483, in _chain_from_iterable_of_lists
for element in iterable:
File "C:\ProgramData\Anaconda3\lib\concurrent\futures\_base.py", line 598, in result_iterator
yield fs.pop().result()
File "C:\ProgramData\Anaconda3\lib\concurrent\futures\_base.py", line 428, in result
return self.__get_result()
File "C:\ProgramData\Anaconda3\lib\concurrent\futures\_base.py", line 384, in __get_result
raise self._exception
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
I have tried putting this in a main command, adding wait, adding [var for var in results], list(results) etc. but to no avail.
N.B. I am on python 3.6

Related

ray.tune.error.TuneError: The Ray Tune run failed

This is from the ray package official code, it works well on Linux systems but appears some errors on windows. All of the ray version is 2.2.0.
import numpy as np
import ray
from ray import air, tune
from ray.air import session
from ray.air.integrations.wandb import setup_wandb
from ray.air.integrations.wandb import WandbLoggerCallback
def train_function(config):
for i in range(30):
loss = config["mean"] + config["sd"] * np.random.randn()
session.report({"loss": loss})
def tune_with_callback():
"""Example for using a WandbLoggerCallback with the function API"""
tuner = tune.Tuner(
train_function,
tune_config=tune.TuneConfig(
metric="loss",
mode="min"
),
run_config=air.RunConfig(
callbacks=[
WandbLoggerCallback(project="Wandb_example")
]
),
param_space={
"mean": tune.grid_search([1, 2, 3, 4, 5]),
"sd": tune.uniform(0.2, 0.8),
},
)
tuner.fit()
if __name__ == '__main__':
tune_with_callback()
And this is printed log with running above python code:
2022-12-30 11:50:41,732 INFO worker.py:1538 -- Started a local Ray instance.
2022-12-30 11:50:46,508 INFO wandb.py:250 -- Already logged into W&B.
Traceback (most recent call last):
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\execution\trial_runner.py", line 928, in _wait_and_handle_event
self._on_pg_ready(next_trial)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\execution\trial_runner.py", line 1018, in _on_pg_ready
if not _start_trial(next_trial) and next_trial.status != Trial.ERROR:
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\execution\trial_runner.py", line 1010, in _start_trial
self._callbacks.on_trial_start(
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\callback.py", line 317, in on_trial_start
callback.on_trial_start(**info)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\logger\logger.py", line 135, in on_trial_start
self.log_trial_start(trial)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\air\integrations\wandb.py", line 527, in log_trial_start
self._trial_processes[trial].start()
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__
reduction.dump(process_obj, to_child)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\air\integrations\wandb.py", line 367, in __reduce__
raise RuntimeError("_WandbLoggingProcess is not pickleable.")
RuntimeError: _WandbLoggingProcess is not pickleable.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\tuner.py", line 272, in fit
return self._local_tuner.fit()
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\impl\tuner_internal.py", line 420, in fit
analysis = self._fit_internal(trainable, param_space)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\impl\tuner_internal.py", line 532, in _fit_internal
analysis = run(
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\tune.py", line
726, in run
runner.step()
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\execution\trial_runner.py", line 981, in step
self._wait_and_handle_event(next_trial)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\execution\trial_runner.py", line 960, in _wait_and_handle_event
raise TuneError(traceback.format_exc())
ray.tune.error.TuneError: Traceback (most recent call last):
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\execution\trial_runner.py", line 928, in _wait_and_handle_event
self._on_pg_ready(next_trial)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\execution\trial_runner.py", line 1018, in _on_pg_ready
if not _start_trial(next_trial) and next_trial.status != Trial.ERROR:
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\execution\trial_runner.py", line 1010, in _start_trial
self._callbacks.on_trial_start(
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\callback.py", line 317, in on_trial_start
callback.on_trial_start(**info)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\logger\logger.py", line 135, in on_trial_start
self.log_trial_start(trial)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\air\integrations\wandb.py", line 527, in log_trial_start
self._trial_processes[trial].start()
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__
reduction.dump(process_obj, to_child)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\air\integrations\wandb.py", line 367, in __reduce__
raise RuntimeError("_WandbLoggingProcess is not pickleable.")
RuntimeError: _WandbLoggingProcess is not pickleable.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\shaohan.tian\Desktop\laptop_python_run\wandb_test.py", line 36, in <module>
tune_with_callback()
File "C:\Users\shaohan.tian\Desktop\laptop_python_run\wandb_test.py", line 33, in tune_with_callback
tuner.fit()
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\site-packages\ray\tune\tuner.py", line 274, in fit
raise TuneError(
ray.tune.error.TuneError: The Ray Tune run failed. Please inspect the previous error messages for a cause. After
fixing the issue, you can restart the run from scratch or continue this run. To continue this run, you can use `tuner = Tuner.restore("C:\Users\shaohan.tian\ray_results\train_function_2022-12-30_11-50-36")`.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "C:\Users\shaohan.tian\scoop\apps\miniconda3\current\envs\steel\lib\multiprocessing\spawn.py", line 126, in _main
self = reduction.pickle.load(from_parent)
EOFError: Ran out of input
I tried modifying versions of ray and wandb, but it was of no use. Could you help me to solve it?

Can't run spider test suite on Windows. Get a runtime error

When I try to run spider test suite like described here:
https://github.com/taoyds/test-suite-sql-eval
I get this error:
Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 125, in _main prepare(preparation_data) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 236, in prepare _fixup_main_from_path(data['init_main_from_path']) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path main_content = runpy.run_path(main_path, File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 289, in run_path return _run_module_code(code, init_globals, run_name, File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 96, in _run_module_code _run_code(code, mod_globals, init_globals, File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\user\PycharmProjects\test-suite-sql-eval\evaluate_classical.py", line 20, in <module> m = Manager() File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\multiprocessing\context.py", line 57, in Manager m.start() File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\multiprocessing\managers.py", line 562, in start self._process.start() File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\multiprocessing\process.py", line 121, in start self._popen = self._Popen(self) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\multiprocessing\context.py", line 336, in _Popen return Popen(process_obj) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__ prep_data = spawn.get_preparation_data(process_obj._name) File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\multiprocessing\spawn.py", line 154, in get_preparation_data _check_not_importing_main() File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\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
Can someome please help?
Thanks!
I tried to run this example command:
python3 evaluate_classical.py --pred=evaluation_examples/classical_test_gold.txt --out_file=all_eval_results.json
I expected to get some kind of evaluation, but got the above error.

ProcessPoolExecutor gets stuck with error: A process in the process pool was terminated abruptly while the future was running or pending

I tried to make a basic program with multiprocessing in Python but I can't get it to work with the concurrent.futures library. Other posts I have found on the topic did not help me either. The program just gets stuck after starting the futures. I have no idea what the reason for that could be. This is my code:
import concurrent.futures
def futureFunction():
print("inside the future")
return 0
def myMethod():
print("start pool...")
with concurrent.futures.ProcessPoolExecutor() as executor:
futs = []
for i in range(4):
print("start future", i)
futs.append(executor.submit(futureFunction))
for f in concurrent.futures.as_completed(futs):
print("done", f.result())
myMethod()
And this is the output I get:
start pool...
start future 0
start future 1
start future 2
start future 3
Why does this happen?
Thanks!
EDIT:
I get this Error when running from a .py file (I am using python 3.6)
start pool...
start future 0
start future 1
start future 2
start future 3
start pool...
start future 0
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 225, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
run_name="__mp_main__")
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\pcuser\Desktop\test.py", line 24, in <module>
myMethod()
File "C:\Users\pcuser\Desktop\test.py", line 18, in myMethod
start pool...
futs.append(executor.submit(futureFunction))
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 466, in submit
start pool...
self._start_queue_management_thread()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 427, in _start_queue_management_thread
self._adjust_process_count()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 446, in _adjust_process_count
start future 0
start future 0
p.start()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\popen_spawn_win32.py", line 33, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
Traceback (most recent call last):
File "<string>", line 1, in <module>
start pool...
_check_not_importing_main()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
is not going to be frozen to produce an executable.''')
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.
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
start pool...
start future 0
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
Traceback (most recent call last):
File "<string>", line 1, in <module>
start pool...
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
Traceback (most recent call last):
File "<string>", line 1, in <module>
start future 0
start future 0
prepare(preparation_data)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
prepare(preparation_data)
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 225, in prepare
Traceback (most recent call last):
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 225, in prepare
start pool...
Traceback (most recent call last):
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
_fixup_main_from_path(data['init_main_from_path'])
File "<string>", line 1, in <module>
_fixup_main_from_path(data['init_main_from_path'])
File "<string>", line 1, in <module>
prepare(preparation_data)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
start future 0
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 295, in _queue_management_worker
shutdown_worker()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 253, in shutdown_worker
call_queue.put_nowait(None)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\queues.py", line 129, in put_nowait
return self.put(obj, False)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\queues.py", line 83, in put
raise Full
queue.Full
Traceback (most recent call last):
File "C:\Users\pcuser\Desktop\test.py", line 24, in <module>
myMethod()
File "C:\Users\pcuser\Desktop\test.py", line 22, in myMethod
print("done", f.result())
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\_base.py", line 425, in result
return self.__get_result()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\_base.py", line 384, in __get_result
raise self._exception
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
C:\Users\pcuser\Desktop>test.py
start pool...
start future 0
start future 1
start future 2
start future 3
start pool...
start future 0
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 225, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
run_name="__mp_main__")
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\pcuser\Desktop\test.py", line 24, in <module>
myMethod()
File "C:\Users\pcuser\Desktop\test.py", line 18, in myMethod
futs.append(executor.submit(futureFunction))
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 466, in submit
self._start_queue_management_thread()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 427, in _start_queue_management_thread
self._adjust_process_count()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 446, in _adjust_process_count
p.start()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\process.py", line 105, in start
self._popen = self._Popen(self)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\context.py", line 223, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\popen_spawn_win32.py", line 33, in __init__
start pool...
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
_check_not_importing_main()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
start pool...
start future 0
is not going to be frozen to produce an executable.''')
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 "<string>", line 1, in <module>
start future 0
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
Traceback (most recent call last):
File "<string>", line 1, in <module>
prepare(preparation_data)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 225, in prepare
exitcode = _main(fd)
start pool...
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
_fixup_main_from_path(data['init_main_from_path'])
prepare(preparation_data)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
start pool...
run_name="__mp_main__")
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 263, in run_path
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 225, in prepare
start future 0
pkg_name=pkg_name, script_name=fname)
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 96, in _run_module_code
start future 0
Traceback (most recent call last):
run_name="__mp_main__")
mod_name, mod_spec, pkg_name, script_name)
File "<string>", line 1, in <module>
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 263, in run_path
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code
pkg_name=pkg_name, script_name=fname)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
Traceback (most recent call last):
File "<string>", line 1, in <module>
exec(code, run_globals)
File "C:\Users\pcuser\Desktop\test.py", line 24, in <module>
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 295, in _queue_management_worker
shutdown_worker()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 253, in shutdown_worker
call_queue.put_nowait(None)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\queues.py", line 129, in put_nowait
return self.put(obj, False)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\queues.py", line 83, in put
raise Full
queue.Full
Traceback (most recent call last):
File "C:\Users\pcuser\Desktop\test.py", line 24, in <module>
myMethod()
File "C:\Users\pcuser\Desktop\test.py", line 22, in myMethod
print("done", f.result())
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\_base.py", line 425, in result
return self.__get_result()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\_base.py", line 384, in __get_result
raise self._exception
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
C:\Users\pcuser\Desktop>test.py
start pool...
start future 0
start future 1
start future 2
start future 3
start pool...
start future 0
Traceback (most recent call last):
File "<string>", line 1, in <module>
start pool...
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 225, in prepare
start future 0
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
Traceback (most recent call last):
start pool...
File "<string>", line 1, in <module>
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
run_name="__mp_main__")
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 263, in run_path
prepare(preparation_data)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 225, in prepare
pkg_name=pkg_name, script_name=fname)
start pool...
start future 0
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\pcuser\Desktop\test.py", line 24, in <module>
myMethod()
File "C:\Users\pcuser\Desktop\test.py", line 18, in myMethod
Traceback (most recent call last):
futs.append(executor.submit(futureFunction))
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 466, in submit
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
start future 0
run_name="__mp_main__")
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 263, in run_path
self._start_queue_management_thread()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 427, in _start_queue_management_thread
self._adjust_process_count()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 446, in _adjust_process_count
File "<string>", line 1, in <module>
Traceback (most recent call last):
pkg_name=pkg_name, script_name=fname)
p.start()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\process.py", line 105, in start
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 96, in _run_module_code
File "<string>", line 1, in <module>
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
self._popen = self._Popen(self)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\context.py", line 223, in _Popen
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
mod_name, mod_spec, pkg_name, script_name)
return _default_context.get_context().Process._Popen(process_obj)
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\context.py", line 322, in _Popen
start pool...
prepare(preparation_data)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 225, in prepare
exec(code, run_globals)
File "C:\Users\pcuser\Desktop\test.py", line 24, in <module>
myMethod()
File "C:\Users\pcuser\Desktop\test.py", line 18, in myMethod
return Popen(process_obj)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\popen_spawn_win32.py", line 33, in __init__
_fixup_main_from_path(data['init_main_from_path'])
start future 0
futs.append(executor.submit(futureFunction))
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 225, in prepare
prep_data = spawn.get_preparation_data(process_obj._name)
start pool...
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 466, in submit
Traceback (most recent call last):
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
start pool...
run_name="__mp_main__")
self._start_queue_management_thread()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 427, in _start_queue_management_thread
start pool...
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
start future 0
_check_not_importing_main()
start pool...
start pool...
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 263, in run_path
File "<string>", line 1, in <module>
self._adjust_process_count()
start future 0
run_name="__mp_main__")
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 136, in _check_not_importing_main
Traceback (most recent call last):
start future 0
pkg_name=pkg_name, script_name=fname)
start future 0
start future 0
start pool...
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 446, in _adjust_process_count
start pool...
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 263, in run_path
Traceback (most recent call last):
is not going to be frozen to produce an executable.''')
File "<string>", line 1, in <module>
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 96, in _run_module_code
Traceback (most recent call last):
Traceback (most recent call last):
Traceback (most recent call last):
exitcode = _main(fd)
p.start()
start future 0
pkg_name=pkg_name, script_name=fname)
File "<string>", line 1, in <module>
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.start future 0
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
mod_name, mod_spec, pkg_name, script_name)
File "<string>", line 1, in <module>
File "<string>", line 1, in <module>
File "<string>", line 1, in <module>
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\process.py", line 105, in start
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 96, in _run_module_code
Traceback (most recent call last):
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code
Traceback (most recent call last):
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 105, in spawn_main
prepare(preparation_data)
self._popen = self._Popen(self)
mod_name, mod_spec, pkg_name, script_name)
File "<string>", line 1, in <module>
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 114, in _main
exec(code, run_globals)
File "<string>", line 1, in <module>
exitcode = _main(fd)
exitcode = _main(fd)
exitcode = _main(fd)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\spawn.py", line 225, in prepare
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\context.py", line 223, in _Popen
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\runpy.py", line 85, in _run_code
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 295, in _queue_management_worker
shutdown_worker()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\process.py", line 253, in shutdown_worker
call_queue.put_nowait(None)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\queues.py", line 129, in put_nowait
return self.put(obj, False)
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\multiprocessing\queues.py", line 83, in put
raise Full
queue.Full
Traceback (most recent call last):
File "C:\Users\pcuser\Desktop\test.py", line 24, in <module>
myMethod()
File "C:\Users\pcuser\Desktop\test.py", line 22, in myMethod
print("done", f.result())
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\_base.py", line 425, in result
return self.__get_result()
File "C:\Users\pcuser\AppData\Local\Programs\Python\Python36\lib\concurrent\futures\_base.py", line 384, in __get_result
raise self._exception
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
EDIT 2:
When I change the method call to:
if __name__ == '__main__':
myMethod()
the problem is fixed for when I run the program from a .py file. But the problem still exists when I try to run the code inside visual studio.
If you just want to solve this problem. You can try to use concurrent.futures.ThreadPoolExecutor(max_workers) in place of concurrent.futures.ProcessPoolExecutor().
The default setting of max_workers is based on the number of CPUs. You can check the documentation of the ThreadPoolExecutor().
If max_workers is None or not given, it will default to the number of processors on the machine, multiplied by 5, assuming that ThreadPoolExecutor is often used to overlap I/O instead of CPU work and the number of workers should be higher than the number of workers for ProcessPoolExecutor.

Python Multiprocessing Traceback (most recent call last)

So I tried making an simple example using the python multiprocessing module.
import time
import multiprocessing
start = time.perf_counter()
def do_something():
print('Sleeping 2 sec ...')
time.sleep(2)
print('Done Sleeping')
p1 = multiprocessing.Process(target=do_something)
p2 = multiprocessing.Process(target=do_something)
p1.start()
p2.start()
p1.join()
p2.join()
finish = time.perf_counter()
print(f'Finished in {round(finish-start, 2)} second(s)')
But when I run it, a very long error traceback is printed:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\Goal\VSB\PDS\Project> & C:/Users/Goal/AppData/Local/Programs/Python/Python39/python.exe
c:/Goal/VSB/PDS/Project/MultiprocessingPython.py
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
exitcode = _main(fd, parent_sentinel)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
prepare(preparation_data)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path
main_content = runpy.run_path(main_path,
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Goal\VSB\PDS\Project\MultiprocessingPython.py", line 14, in <module>
exec(code, run_globals)
File "c:\Goal\VSB\PDS\Project\MultiprocessingPython.py", line 14, in <module>
p1.start()
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py",
line 121, in start
p1.start()
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py",
line 121, in start
self._popen = self._Popen(self)
self._popen = self._Popen(self)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py",
line 224, in _Popen
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py",
line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py",
line 327, in _Popen
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py",
line 327, in _Popen
return Popen(process_obj)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
return Popen(process_obj)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
_check_not_importing_main()
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\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.
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()
...
ne 134, in _check_not_importing_main
_check_not_importing_main()
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\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.
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.
Finished in 0.2 second(s)
PS C:\Goal\VSB\PDS\Project> & C:/Users/Goal/AppData/Local/Programs/Python/Python39/python.exe
c:/Goal/VSB/PDS/Project/MultiprocessingPython.py
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main
exitcode = _main(fd, parent_sentinel)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main
prepare(preparation_data)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code
Traceback (most recent call last):
File "<string>", line 1, in <module>
_run_code(code, mod_globals, init_globals,
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 116, in spawn_main
exec(code, run_globals)
File "c:\Goal\VSB\PDS\Project\MultiprocessingPython.py", line 14, in <module>
exitcode = _main(fd, parent_sentinel)
p1.start()
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 125, in _main
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py",
line 121, in start
prepare(preparation_data)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 236, in prepare
self._popen = self._Popen(self)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py",
line 224, in _Popen
_fixup_main_from_path(data['init_main_from_path'])
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 287, in _fixup_main_from_path
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py",
line 327, in _Popen
main_content = runpy.run_path(main_path,
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 268, in run_path
return Popen(process_obj)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
return _run_module_code(code, init_globals, run_name,
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 97, in _run_module_code
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_run_code(code, mod_globals, init_globals,
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
_check_not_importing_main()
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 134, in _check_not_importing_main
exec(code, run_globals)
File "c:\Goal\VSB\PDS\Project\MultiprocessingPython.py", line 14, in <module>
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. p1.start()
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\process.py",
line 121, in start
self._popen = self._Popen(self)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py",
line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py",
line 327, in _Popen
return Popen(process_obj)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\popen_spawn_win32.py", line 45, in __init__
prep_data = spawn.get_preparation_data(process_obj._name)
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py", line 154, in get_preparation_data
_check_not_importing_main()
File "C:\Users\Goal\AppData\Local\Programs\Python\Python39\lib\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.
Finished in 0.16 second(s)
PS C:\Goal\VSB\PDS\Project>
And there are so many things here I don't know if they can be called error? They are just so many that I dont even know what to search on the internet to solve my problem.
When Python throws these massive error statements, make sure to know what you are looking for- the important part to notice is that the error is stemming from a raise call, meaning that you need to look after the raise keywords in the error text.
As you can see, the actual text error thrown (The text found after the line with the raise keyword) is the following:
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.
After that, you can easily search this up and find a very helpful and detailed answer here (TLDR: You need to use if __name__ == '__main__': so that the code does not recursively import).

Alembic execute SQL as part of migration

I want alembic to get the current stored procedure from DB compare it to the one in the code. If they are different to update the DB.
I edited the env.py file to check for this, and generate an upgrade versions of the raw SQL.
when running the following :
writer = rewriter.Rewriter()
#writer.rewrites(ops)
def stored_procedure(context, revision, op):
if not change_detected():
print("did not detect difference in stored procedure.")
return op
else:
print("detected difference in stored")
package_sql = open(migration_file_path, "r")
package_sql = migration_file.read()
package_sql = '"""' + package_sql + '"""'
return [
op,
op.get_bind().execute(package_sql),
]
Traceback (most recent call last):
File "c:\Project\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\ptvsd_launcher.py", line 43, in <module>
main(ptvsdArgs)
File "c:\Project\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\lib\python\ptvsd\__main__.py", line 432, in main
run()
File "c:\Project\.vscode\extensions\ms-python.python-2019.9.34911\pythonFiles\lib\python\ptvsd\__main__.py", line 316, in run_file
runpy.run_path(target, run_name='__main__')
File "C:\Project\Programs\Python\Python37\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "C:\Project\Programs\Python\Python37\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "C:\Project\Programs\Python\Python37\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:/Project/manage.py", line 15, in <module>
manager.run()
...
File "C:\Project\ENV\lib\site-packages\alembic\runtime\migration.py", line 351, in run_migrations
for step in self._migrations_fn(heads, self):
File "C:\Project\ENV\lib\site-packages\alembic\command.py", line 173, in retrieve_migrations
revision_context.run_autogenerate(rev, context)
File "C:\Project\ENV\lib\site-packages\alembic\autogenerate\api.py", line 433, in run_autogenerate
self._run_environment(rev, migration_context, True)
File "C:\Project\ENV\lib\site-packages\alembic\autogenerate\api.py", line 483, in _run_environment
hook(migration_context, rev, self.generated_revisions)
File "migrations\env.py", line 167, in process_revision_directives
stored_procedure(context, revision, directives)
File "migrations\env.py", line 146, in stored_procedure
op.get_bind().execute(package_sql),
AttributeError: 'list' object has no attribute 'get_bind'

Categories