【python】RuntimeError: Lock objects should only be shared between processes through inheritance
2013-09-09 10:15
816 查看
在使用multiprocessing模块时,使用了同步锁Lock,结果出现了如下错误:
RuntimeError: Lock objects should only be shared between processes through inheritance
我本来是这样用的:
估计是用了进程池,而进程池中的进程并不是由当前同一个父进程创建的原因。查了下资料,multiprocessing.Manager()返回的manager对象控制了一个server进程,可用于多进程之间的安全通信,其支持的类型有list,dict,Namespace,Lock,RLock,Semaphore,BoundedSemaphore,Condition,Event,Queue,Value和Array等。
所以代码修改成这样后就可以正常运行了:
RuntimeError: Lock objects should only be shared between processes through inheritance
我本来是这样用的:
lock = multiprocessing.Lock() pool = multiprocessing.Pool(processes=3) for i in range(0,3): pool.apply_async(child_worker, ((my_parameter, lock),)) pool.close() pool.join()
估计是用了进程池,而进程池中的进程并不是由当前同一个父进程创建的原因。查了下资料,multiprocessing.Manager()返回的manager对象控制了一个server进程,可用于多进程之间的安全通信,其支持的类型有list,dict,Namespace,Lock,RLock,Semaphore,BoundedSemaphore,Condition,Event,Queue,Value和Array等。
所以代码修改成这样后就可以正常运行了:
lock = multiprocessing.Manager().Lock() pool = multiprocessing.Pool(processes=3) for i in range(0,3): pool.apply_async(child_worker, ((my_parameter, lock),)) pool.close() pool.join()
相关文章推荐
- 【python】RuntimeError: Lock objects should only be shared between processes through inheritance
- python multiprocess.Queue - RuntimeError: Queue objects should only be shared between processes through inheritance
- 多线程下,Python Sqlite3报[SQLite objects created in a thread can only be used...]问题
- Python SQLite3的问题sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in th
- 安装Ecshop首页出现报错:Only variables should be passed by referen
- 安装ECSHOP错误,Strict Standards: Only variables should be passed by reference
- Error: CompareBaseObjectsInternal can only be called from the main thread
- Only one statement is allowed per batch. A batch separator, such as 'GO', might be required between statements.
- persistence.cpp:2197:ann.xml(1): There should be space between attributes in function icvXMLParseTag
- PHP 调试报“Only variables should be passed by reference”解决办法!
- 安装 ecshop后报错 Strict standards: Only variables should be passed by reference in
- python3爬虫问题 POST data should be bytes or an iterable of bytes
- 安装Ecshop首页出现报错:Only variables should be passed by referen
- Notice: Only variable references should be returned by reference(PHP版本兼容性问题)
- Error: Mock locations should only be requested in a test or debug-specific manifest file
- 关于python2.7的md5加密遇到的问题(TypeError: Unicode-objects must be encoded before hashing)
- Only variable references should be returned by reference
- C++编译错误"a storage class can only be specified for objects and functions"解决方法
- 安装Ecshop首页出现报错:Only variables should be passed by referen
- python3.x执行post请求时报错“POST data should be bytes or an iterable of bytes...”的解决方法