环境:
Appium Desktop V1.7.2 + python 3.6 + Mac 10.12.6
前提:
1. 通过代码自动开启两个Appium进程
2. 通过multiprocessing.Pool()开启子进程
3. 子进程放在unittest框架中执行,并且appium连接启动手机APP的方法也在子进程中执行
问题:
脚本执行下面代码时,python编译器会出现crash
webdriver.Remote("http://127.0.0.1:" + self.param['p'] + "/wd/hub", self.desired_caps)
查看report后发现问题为:
***multi-thread process forked *** crashed on child side of fork pre-exec
解决方法:
因为在Linux/ Mac, 使用multiprocessing.Pool()时,默认是用fork方式开启子进程,那么就修改开启子进程的方法既可。
-
multiprocessing.set_start_method('spawn') /
-
multiprocessing.set_start_method( 'forkserver')
Note:
multiprocessing.set_start_method()只能用在主进程中
参考链接:
https://stackoverflow.com/questions/25260000/scik6it-learns-gridsearchcv-stops-working-when-n-jobs1
https://docs.python.org/dev/library/multiprocessing.html#contexts-and-start-methods
转自: Oops_newbie的博客