已解决RuntimeError: An attempt has been made to start a new process before the current process has fi
解决 to The an has New Process start
2023-09-27 14:27:32 时间
已解决RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase.
报错问题
粉丝群里面的一个小伙伴敲代码时发生了报错(当时他心里瞬间凉了一大截,跑来找我求助,然后顺利帮助他解决了,顺便记录一下希望可以帮助到更多遇到这个bug不会解决的小伙伴),报错信息如下:
解决方法
解决方法如下
通过main方法来执行python文件
# TODO 进程池的使用
from multiprocessing import Pool
import os, time, random
def worker(msg):
t_start = time.time()
print("%s开始执行,进程号为%d" % (msg,os.getpid()))
# random.random()随机生成0~1之间的浮点数
time.sleep(random.random()*2)
t_stop = time.time()
print(msg,"执行完毕,耗时%0.2f" % (t_stop-t_start))
def main():
# 定义一个进程池,最大进程数3
p = Pool(3)
for i in range(0,10):
# Pool().apply_async(要调用的目标,(传递给目标的参数元祖,))
# 每次循环将会用空闲出来的子进程去调用目标
p.apply_async(worker,(i,))
print("----start----")
p.close() # 关闭进程池,关闭后po不再接收新的请求
p.join() # 等待po中所有子进程执行完成,必须放在close语句之后
print("-----end-----")
if __name__ == '__main__':
main()
福利
每周会送6本技术书籍包邮到家
由于博主时间精力有限,每天私信人数太多,没办法每个粉丝都及时回复
大家可以进社区裙或者添加博主微信
点击下方链接即可
http://t.csdn.cn/6kInJ
相关文章
- 解决 The 'InnoDB' feature is disabled; you need MySQL built with 'InnoDB' to have it working
- 使用selenium启动火狐浏览器,解决Unable to create new remote session问题
- 解决Maven打包时报错"The packaging for this project did not assign a file to the build artifact"
- cURL error 60: SSL certificate problem: unable to get local issuer certifica 解决
- 68Linux - 解决CentOS启动卡住了,提示starting auditd: [failed]
- 解决Navicat报错:2013 - Lost connection to MySQL server during query
- Host is not allowed to connect to this MySQL server解决方法
- [转]解决Cannot change version of project facet Dynamic web module to 2.5
- 解决git命令会将结果输出到单独窗口必须按q才能退出的问题
- The connection to adb is down, and a severe error has occured.问题解决
- The connection to adb is down, and a severe error has occured.问题解决
- apt-get install报错E: Failed to fetch问题解决
- Failed to get D-Bus connection: Operation not permitted解决
- vmware Unable to open kernel device ".Globalvmx86": The system cannot find the file 的解决方法
- 解决Warning: NEWFF used in an obsolete way. See help for NEWFF to update calls to the new argument li
- 关闭 You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- 解决Cannot change version of project facet Dynamic web module to 2.5
- SVN解决Unable to create pristine install stream
- Failed to resolve: com.android.support:appcompat-v7:27.+ 报错解决方法
- C# linq to entity中字段转化为指定类型 lambda 字段类型转换 解决"LINQ to Entities does not recognize the method 'System.String ToString(Int32)' method, and this method cannot be translated into a store expression."
- 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法!
- Git报错记录:refusing to merge unrelated histories、There is no tracking information for the current branch、如何解决Git报错:更新被拒绝是因为推送的分支提示位于其远程对方后面
- iOS ERROR: unable to get the receiver data from the DB 解决方式
- 没有找到MSVCR100.dll解决方法
- [已解决]报错:Failed to restart network.service: Unit network.service not found
- 数据结构-解决hash冲突的三个方法
- 解决Can‘t uninstall ‘docker‘. No files were found to uninstall.不能卸载方法
- 版本控制工具 Git SourceTree 登录信息等被我删除了 解决
- 多种方式解决Java控制台报错 java.util.LinkedHashMap cannot be cast to.....
- 2. 成功解决 BUG:Exception when publishing, ...[Failed to connect and initialize SSH connection...