windows在启动子进程的时候会将主进程文件倒入到子进程中。导入模块就相当于执行这个模块中的代码,

所以第一个print会在主进程中执行一次,又在被导入的过程中在子进程中又执行了一次。

p.start()过程中会调用一次当前模块

注意:在windows中Process()必须放到# if __name__ == '__main__':下

Since Windows has no fork, the multiprocessing module starts a new Python process and imports the calling module.
If Process() gets called upon import, then this sets off an infinite succession of new processes (or until your machine runs out of resources).
This is the reason for hiding calls to Process() inside

if __name__ == "__main__"
since statements inside this if-statement will not get called upon import.
由于Windows没有fork,多处理模块启动一个新的Python进程并导入调用模块。
如果在导入时调用Process(),那么这将启动无限继承的新进程(或直到机器耗尽资源)。
这是隐藏对Process()内部调用的原,使用if __name__ == “__main __”,这个if语句中的语句将不会在导入时被调用。

Since Windows has no fork, the multiprocessing module starts a new Python process and imports the calling module.
If Process() gets called upon import, then this sets off an infinite succession of new processes (or until your machine runs out of resources).
This is the reason for hiding calls to Process() inside if __name__ == "__main__"
since statements inside this if-statement will not get called upon import.
由于Windows没有fork,多处理模块启动一个新的Python进程并导入调用模块。
如果在导入时调用Process(),那么这将启动无限继承的新进程(或直到机器耗尽资源)。
这是隐藏对Process()内部调用的原,使用if __name__ == “__main __”,这个if语句中的语句将不会在导入时被调用。

windows下创建子进程过程中代码重复执行问题的更多相关文章

  1. windows下jenkins安装过程中的那些坑

    在jenkins官网https://jenkins.io/download/下载2.89.4版本的war包,使用jar -jar jenkins.war命令安装,报端口被占的错误,使用jar -jar ...

  2. windows下python-nmap运行过程中出现的问题及解决办法

    python-nmap 运行时出现了一下错误 D:\python\untitled5\Scripts\python.exe D:/python/untitled5/test.py Traceback ...

  3. Tomcat7.0.22在Windows下详细配置过程

    Tomcat7.0.22在Windows下详细配置过程 一.JDK1.7安装 1.下载jdk,下载地址:http://www.oracle.com/technetwork/java/javase/do ...

  4. iOS下KVO使用过程中的陷阱 (转发)

    iOS下KVO使用过程中的陷阱   KVO,全称为Key-Value Observing,是iOS中的一种设计模式,用于检测对象的某些属性的实时变化情况并作出响应.网上广为流传普及的一个例子是利用KV ...

  5. windows下创建Python虚拟环境

    windows下创建Python虚拟环境 说明 由于Python的版本众多,还有Python2和Python3的争论,因此有些软件包或第三方库就容易出现版本不兼容的问题. 通过 virtualenv ...

  6. Git - git bash 在 windows 下创建软连接

    1. 概述 使用 git bash 在 windows 下创建软连接 或者叫 快捷方式 感谢 Tony 老师的帮助 Tony 的技术笔记 Windows 使用 ln -s 创建软链接 2. 问题 需求 ...

  7. windows下创建/删除服务

    windows下创建/删除服务 1.      windows下创建/删除服务 1.1.    创建服务 命令格式: sc [servername] create Servicename [Optio ...

  8. 在Linux下安装PHP过程中,编译时出现错误的解决办法

    在Linux下安装PHP过程中,编译时出现configure: error: libjpeg.(a|so) not found 错误的解决办法 configure: error: libjpeg.(a ...

  9. 在windows下的QT编程中的_TCHAR与QString之间的转换

    由于在windows下的QT编程中,如果涉及到使用微软的API,那么不可避免使用_TCHAR这些类型,因此在网上查了一下,其中一个老外的论坛有人给出了这个转换,因此在这里做一下笔记 : )#ifdef ...

随机推荐

  1. 执行ng build --prod --aot命令报错

    D:\git\**\src\main\iui>ng build --prod --aotHash: 257ab60feca43633b6f7Time: 25358mschunk {0} poly ...

  2. webpack.config.js====插件purifycss-webpack,提炼css文件

    1. 安装:打包编译时,可以删除一些html中没有使用的选择器,如果html页面中没有class=a class="b"的元素,.a{}.b{}样式不会加载 cnpm instal ...

  3. ios 绘制虚线 CGContextSetLineDash的使用

    画虚线需要用到函数: CGContextSetLineDash 此函数需要四个参数: context – 这个不用多说 phase - 稍后再说 lengths – 指明虚线是如何交替绘制,具体看例子 ...

  4. Nginx FastCGI PHP

    We can see this comment in nginx.conf. # pass the PHP scripts to FastCGI server listening on 127.0.0 ...

  5. Unity runtime性能分析器

    一. Profiler: 1. CPU Usage A. WaitForTargetFPS: Vsync(垂直同步)功能所,即显示当前帧的CPU等待时间 B. Overhead: Profiler总体 ...

  6. python_98_面向对象_学校

    class School(object):#以后都加object(基类) def __init__(self, name, addr): self.name = name self.addr = ad ...

  7. s///|s()()i|/i|/g|\U|\u|\L|\l|\U\l|split|join|匹配到hash|匹配到变量|`date`|$^I

    #!/usr/bin/perl -w use strict; use warnings; $_='She is a good girl and likes helping others '; s/sh ...

  8. Shell脚本调用ftp上传文件

    Shell脚本调用ftp上传文件 1.脚本如下 ftp -n<<! open x.x.x.x ###x.x.x.x为ftp地址 user username password ###user ...

  9. Spring中使用事务搭建转账环境方法二 相对简便的注解方法 ——配置文件注入对象属性需要setter方法 注解方法,不需要生成setter方法

    XML配置文件代码如下: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=" ...

  10. mac 使用homebrew 安装mysql

    1. 安装homebrew ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" brew update ...