python进程池multiprocessing.Pool运行错误:The "freeze_support()" line can be omitted if the program is not g
来源:互联网 发布:java对象锁和类锁 编辑:程序博客网 时间:2024/05/18 19:45
测试代码如下:
# -*- coding: utf-8 -*-import multiprocessingimport timedef func(msg): print('msg: ', msg) time.sleep(1) print('----')pool = multiprocessing.Pool(processes=4)for i in range(10): msg = 'hello world %d' % i pool.apply_async(func, (msg, ))pool.close()pool.join()
上面的代码运行将产生如下错误信息:
RuntimeError: An attempt has been made to start a new process before the current process has finished its . 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.
从错误信息可以看出进程池相关代码应该放在if __name__ == '__main__'下面,代码修改如下:
# -*- coding: utf-8 -*-import multiprocessingimport timedef func(msg): print('msg: ', msg) time.sleep(1) print('----')if __name__ == '__main__': pool = multiprocessing.Pool(processes=4) for i in range(10): msg = 'hello world %d' % i pool.apply_async(func, (msg, )) pool.close() pool.join()
0 0
- python进程池multiprocessing.Pool运行错误:The "freeze_support()" line can be omitted if the program is not g
- python进程池:multiprocessing.pool
- python进程池:multiprocessing.pool
- python进程池:multiprocessing.pool
- python进程池:multiprocessing.pool
- python进程池:multiprocessing.pool
- 【Python】python进程池:multiprocessing.pool
- Python thread pool similar to the multiprocessing Pool?
- multiprocessing 进程池 pool
- Python多进程multiprocessing.Pool()
- Visiting the Ikea stores can be very overwhelming even if it is not your first time. If it is your first time
- ubuntu14.10 安装maven出现The program 'mvn' can be found in the following packages错误
- python进程池multiprocessing.Pool和线程池multiprocessing.dummy.Pool实例
- spring使用AOP时the prefix aop for element is not bound.和no declaration can be found错误
- The program 'java' can be found in the following packages
- Python通过上下文管理器使用进程池multiprocessing.Pool
- Texture ‘XXX' is not readable, the memory can not be accessed form scripts, You can make the texture
- Texture ‘XXX' is not readable, the memory can not be accessed form scripts, You can make the texture
- 大话数据结构学习笔记1
- C++程序编程步骤
- FastJson--阿里巴巴公司开源的速度最快的Json和对象转换工具
- C++ new的用法
- UNet系统初次使用——联网Boxing游戏(2)
- python进程池multiprocessing.Pool运行错误:The "freeze_support()" line can be omitted if the program is not g
- POJ 3422 Kaka's Matrix Travels
- Kth Largest Element 解题报告
- 测试用例知识点总结
- .NET WebBrowser不与IE或其他进程共享cookie(WebBrowser独立cookie方法)
- 阿里云线上云服务器(linux)上创建用户并付权限
- 解决 go get 撞墙问题
- Mac 安装 adb (Android调试桥)
- 进程间传递文件描述符--sendmsg,recvmsg(可用)