在Windows上可能遇到,开启的子进程不会关闭的问题

参考multiprocessing官方文档:

Explicitly pass resources to child processes

On Unix a child process can make use of a shared resource created in a parent process using a global resource. However, it is better to pass the object as an argument to the constructor for the child process.

Apart from making the code (potentially) compatible with Windows this also ensures that as long as the child process is still alive the object will not be garbage collected in the parent process. This might be important if some resource is freed when the object is garbage collected in the parent process.

So for instance

from multiprocessing import Process, Lock

def f():
... do something using "lock" ... if __name__ == '__main__':
lock = Lock()
for i in range(10):
Process(target=f).start()

should be rewritten as

from multiprocessing import Process, Lock

def f(l):
... do something using "l" ... if __name__ == '__main__':
lock = Lock()
for i in range(10):
Process(target=f, args=(lock,)).start()

multiprocessing跨平台锁的使用(Windows问题)的更多相关文章

  1. ISE(Iris Server Engine)是一个基于现代C++的跨平台(Linux和Windows)框架

    ISE(Iris Server Engine)是一个基于现代C++的跨平台(Linux和Windows)的高性能多线程并发网络服务器程序框架.它封装了琐碎的socket以及各种操作系统APIs,以面向 ...

  2. <学习opencv>跨平台和本机windows

    /*=========================================================================*/ // 跨平台和本机Windows /*=== ...

  3. 进程Process之join、daemon(守护)、terminate(关闭)、multiprocessing之锁、信号量和事件

    一.Process 参数介绍: 1 group参数未使用,值始终为None 2 target表示调用对象,即子进程要执行的任务 3 args表示调用对象的位置参数元组,args=(1,2,'a',) ...

  4. 使用Active Database Duplication创建跨平台Data Guard设置 (Windows/Linux) (Doc ID 881421.1)

    Using Active Database Duplication to Create Cross Platform Data Guard Setup (Windows/Linux) (Doc ID ...

  5. .NET Core 跨平台 串口通讯 ,Windows/Linux 串口通讯,flyfire.CustomSerialPort 的使用

    目录 1,前言 2,安装虚拟串口软件 3,新建项目,加入 flyfire.CustomSerialPort 4,flyfire.CustomSerialPort 说明 5,开始使用 flyfire.C ...

  6. 跨平台的EVENT事件 windows linux

    #ifndef _HIK_EVENT_H_ #define _HIK_EVENT_H_ #ifdef _MSC_VER #include <Windows.h> #define hik_e ...

  7. golang 跨平台编译——go 在windows上编译Linux平台的程序(Cross Compilation from Windows to Linux/Ubuntu)

    Go Cross Compilation from Windows to Linux/Ubuntu I have GO 1.7 installed on my Windows 10. I create ...

  8. 跨平台的EVENT事件 windows linux(转)

    #ifndef _HIK_EVENT_H_ #define _HIK_EVENT_H_ #ifdef _MSC_VER #include <Windows.h> #define hik_e ...

  9. H5程序员如何利用cordova开发跨平台应用

    什么是Cordova? Cordova以前也叫PhoneGap,它提供了一组设备相关的API,通过这组API,移动应用能够以JavaScript访问原生的设备功能,如摄像头.麦克风等.Cordova还 ...

随机推荐

  1. 高手总结的CSS执行顺序及其优先权问题汇总

    今天在看一本书时又看到了”CSS优 先权“这个问题,感觉这个问题还是比较重要的,也算是样式的特异性吧,尤其是在面对较多.较深层.较复杂的样式属性时,理解CSS的加权计算方法对于重写 样式属性之类的问题 ...

  2. js 图片无缝循环

    <html> <head> <title>Js图片无缝滚动</title> <style type="text/css"> ...

  3. Keil C51.uew

    /L15"Keil C51" Line Comment = // Block Comment On = /* Block Comment Off = */ Escape Char ...

  4. shell字符串

    字符串是shell编程中最常用最有用的数据类型(除了数字和字符串,也没啥其它类型好用了),字符串可以用单引号,也可以用双引号,也可以不用引号.单双引号的区别跟PHP类似. 单引号 str='this ...

  5. UESTC_Sea Base Exploration CDOJ 409

    When the scientists explore the sea base, they use a kind of auto mobile robot, which has the missio ...

  6. poj1001(高精度)

                                                               Exponentiation Time Limit: 500MS   Memory ...

  7. (step6.1.3)hdu 1875(畅通工程再续——最小生成树)

    题目大意:本题是中文题,可以直接在OJ上看 解题思路:最小生成树 1)本题的关键在于把二维的点转化成一维的点 for (i = 0; i < n; ++i) { scanf("%d%d ...

  8. [C# 基础知识系列]专题九: 深入理解泛型可变性

    引言: 在C# 2.0中泛型并不支持可变性的(可变性指的就是协变性和逆变性),我们知道在面向对象的继承中就具有可变性,当方法声明返回类型为Stream,我们可以在实现中返回一个FileStream的类 ...

  9. 【bzoj1031】[JSOI2007]字符加密Cipher

    题目描述 喜欢钻研问题的JS同学,最近又迷上了对加密方法的思考.一天,他突然想出了一种他认为是终极的加密办法:把需要加密的信息排成一圈,显然,它们有很多种不同的读法.例如下图,可以读作:JSOI07 ...

  10. 通过dataflow导入customer

    本文在Magento ver.1.9.1.1上测试通过 (1)在配置文件中设置对应的选项.如果是多website,记得选择相应的website下的store.如果没有添加新的website,建议还是选 ...