vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 12
声望: 2

以命令方式执行多进程优化的时候,报以下错误,请问如何解决:

2020-10-09 16:52:59.924560 开始加载历史数据
2020-10-09 16:53:00.023296 加载进度:########## [100%]
2020-10-09 16:53:00.023296 历史数据加载完成,数据量:41761
2020-10-09 16:53:00.322496 开始加载历史数据
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "D:\vnstudio\lib\multiprocessing\spawn.py", line 105, in spawn_main
exitcode = _main(fd)
File "D:\vnstudio\lib\multiprocessing\spawn.py", line 114, in _main
prepare(preparation_data)
File "D:\vnstudio\lib\multiprocessing\spawn.py", line 225, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "D:\vnstudio\lib\multiprocessing\spawn.py", line 277, in _fixup_main_from_path
run_name="mp_main")
File "D:\vnstudio\lib\runpy.py", line 263, in run_path
pkg_name=pkg_name, script_name=fname)
File "D:\vnstudio\lib\runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "D:\vnstudio\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "D:\Pycharm\vnpy-master\vnpy\app\cta_strategy\backtesting\backtesting_demo_multiprocess.py", line 53, in <module>
engine.run_optimization(setting)
File "D:\Pycharm\vnpy-master\vnpy\app\cta_strategy\backtesting.py", line 578, in run_optimization
pool = ctx.Pool(multiprocessing.cpu_count())
File "D:\vnstudio\lib\multiprocessing\context.py", line 119, in Pool
context=self.get_context())
File "D:\vnstudio\lib\multiprocessing\pool.py", line 177, in init
self._repopulate_pool()
File "D:\vnstudio\lib\multiprocessing\pool.py", line 238, in _repopulate_pool
self._wrap_exception)
File "D:\vnstudio\lib\multiprocessing\pool.py", line 257, in _repopulate_pool_static
w.start()
File "D:\vnstudio\lib\multiprocessing\process.py", line 112, in start
self._popen = self._Popen(self)
File "D:\vnstudio\lib\multiprocessing\context.py", line 322, in _Popen
return Popen(process_obj)
File "D:\vnstudio\lib\multiprocessing\popen_spawn_win32.py", line 33, in init
prep_data = spawn.get_preparation_data(process_obj._name)
File "D:\vnstudio\lib\multiprocessing\spawn.py", line 143, in get_preparation_data
_check_not_importing_main()
File "D:\vnstudio\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.
Member
avatar
加入于:
帖子: 1761
声望: 116

错误原因应该是多进程需要在main函数中运行。建议多进程优化还是在jupyter或者图形界面上操作好一些。

Member
avatar
加入于:
帖子: 12
声望: 2

我是计划在centos 服务器上运行多进程或遗传算法优化,都是命令操作的,有没有解决办法呢?
jupter可用通过命令操作吗
谢谢~

Administrator
avatar
加入于:
帖子: 4449
声望: 255

jupyter可以启动网页服务器,然后远程访问即可

© 2015-2019 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号-3

沪公网安备 31011502017034号