zoukankan      html  css  js  c++  java
  • windows下创建子进程过程中代码重复执行问题

    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语句中的语句将不会在导入时被调用。
  • 相关阅读:
    机器学习 之 SVM VC维度、样本数目与经验风险最小化的关系
    password学4——Java 加密解密之消息摘要算法(MD5 SHA MAC)
    JavaScript实现类的private、protected、public、static以及继承
    android:3D垂直翻转动画-FlipAnimation
    生产者消费者问题
    01串
    html5+css3 权威指南阅读笔记(三)---表单及其它新增和改良元素
    Android xUtils3源代码解析之网络模块
    mysql5.7切换导致gtid不一致
    mysql简单优化的一些总结
  • 原文地址:https://www.cnblogs.com/ellisonzhang/p/10440310.html
Copyright © 2011-2022 走看看