假如使用Process创建子进程,那么在最后的函数调用时需要加上if __name__ == "__main__":语句,否则会报错。

未使用该语句

代码示例

from multiprocessing import Process

def test_input():
print("start print info!") Process(target=test_input).start()

结果示例

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.

使用该语句

代码示例

from multiprocessing import Process

def test_input():
print("start print info!") if __name__ == '__main__':
Process(target=test_input).start()

结果示例

start print info!

Process finished with exit code 0

在Python中使用Process创建子进程遇到的问题的更多相关文章

  1. [转载]Python模块学习 ---- subprocess 创建子进程

    [转自]http://blog.sciencenet.cn/blog-600900-499638.html 最近,我们老大要我写一个守护者程序,对服务器进程进行守护.如果服务器不幸挂掉了,守护者能即时 ...

  2. Python 使用 os.fork() 创建子进程

    Linux 操作系统提供了一个 fork() 函数用来创建子进程,这个函数很特殊,调用一次,返回两次,因为操作系统是将当前的进程(父进程)复制了一份(子进程),然后分别在父进程和子进程内返回.子进程永 ...

  3. 为什么python2.7中用Process创建子进程的语句之前必须加#if

    from multiprocessing import Process import os def run(name): print 'The child process '%s' (pid %d) ...

  4. python中利用类创建的对象来保存信息

    在类创建的对象中,一般都是以字典的方式来保存信息 class Student: def __init__(self, name, age, score): self.name = name self. ...

  5. python中的Process

    from multiprocessing import Process import time import os # # def acb(n): # print(n) # # # if __name ...

  6. Python中subprocess 模块 创建并运行一个进程

     python的subprocess模块,看到官方声明里说要尽力避免使用shell=True这个参数,于是测试了一下: from subprocess import call import shlex ...

  7. Python 中使用动态创建类属性的机制实现接口之后的依赖

    我们在自动化测试中经常会需要关联用例处理,需要动态类属性: 推荐使用第二种方法: 创建:setattr() 获取:getattr() 两种,如何创建 类属性 loan_id # 第一种,创建 # 类名 ...

  8. Python中通过threshold创建mask

    [code] import numpy as np threshold=2 a=np.array([[1,2,3],[3,4,5]]) b=a>threshold print("a=& ...

  9. python中单例模式的创建

    # 单例模式(使用装饰器) def singleton(cls): instance = {} def wrapper(*args,**kwargs): if cls not in instance: ...

  10. 8.python中的数字

    python中数字对象的创建如下, a = 123 b = 1.23 c = 1+1j 可以直接输入数字,然后赋值给变量. 同样也可是使用类的方式: a = int(123) b = float(1. ...

随机推荐

  1. ASR项目实战-决策点

    针对语音识别的产品,分别记录设计.开发过程中的决策点. 实时语音识别 对于实时语音识别来说,客户端和服务端之间实时交换语音数据和识别的结果. 客户端在启动识别时,即开始发送语音数据,期望在等待较短的时 ...

  2. 【ASP.NET Core】使用SignalR推送服务器日志

    一个多月前接手了一个产线机器人项目,上位机以读写寄存器的方式控制机器人,服务器就是用 ASP.NET Core 写的 Web API.由于前一位开发者写的代码质量问题,导致上位机需要16秒才能启动.经 ...

  3. 搭建vulfocus靶场

    搭建vulfocus靶场 第一种方法 docker pull一下执行如下命令即可 docker pull vulfocus/vulfocus:latest docker run -d -p 8081: ...

  4. Windows 7更新失败的解决方法

    你好,1.在开始菜单中点击运行,→输入"services.msc"→找到"windows update"右击选择"停止":2.进入C:\wi ...

  5. VisionPro学习笔记(6)——如何使用QuickBuild

    如果需要了解其他图像处理的文章,请移步小编的GitHub地址 传送门:请点击我 如果点击有误:https://github.com/LeBron-Jian/ComputerVisionPractice ...

  6. 文心一言 VS 讯飞星火 VS chatgpt (57)-- 算法导论6.4 1题

    文心一言 VS 讯飞星火 VS chatgpt (57)-- 算法导论6.4 1题 一.参照图 6-4 的方法,说明 HEAPSORT 在数组 A=(5,13,2,25,7,17,20,8,4)上的操 ...

  7. 关于GO语言,这篇文章讲的很明白

    摘要:本文从Go的语法,类型系统,编码风格,语言工具,编码工具和使用案例等几方面对Go语言进行了学习和探讨. Go语言发布之后,很多公司特别是云厂商也开始用Go语言重构产品的基础架构,而且很多企业都是 ...

  8. 云图说|图解制品仓库CodeArts Artifact

    摘要:制品仓库用于存放由源码编译生成的.可运行的二进制文件,重要作用是实现制品文件的可信存储,支撑软件开发活动. 本文分享自华为云社区<[云图说]第277期 图解制品仓库CodeArts Art ...

  9. LiteOS:剖析时间管理模块源代码

    摘要:Huawei LiteOS的时间管理模块以系统时钟为基础,分为2部分,一部分是SysTick中断,为任务调度提供必要的时钟节拍:另外一部分是,给应用程序提供所有和时间有关的服务,如时间转换.统计 ...

  10. 一文详解特权访问管理(PAM)

    什么是特权访问管理(PAM)? 特权访问管理(Privileged Access Management)是一个包含网络安全策略和访问管理工具的解决方案,用于控制和监管和保护具有特权访问权限的用户.在之 ...