【python】RuntimeError: Lock objects should only be shared between processes through inheritance
2017-12-26 14:54
806 查看
转自:http://blog.csdn.net/moxiaomomo/article/details/11470157
在使用multiprocessing模块时,使用了同步锁Lock,结果出现了如下错误:RuntimeError: Lock objects should only be shared between processes through inheritance
我本来是这样用的:[python] view plain copylock = 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等。 所以代码修改成这样后就可以正常运行了:[python] view plain copylock = 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()
在使用multiprocessing模块时,使用了同步锁Lock,结果出现了如下错误:RuntimeError: Lock objects should only be shared between processes through inheritance
我本来是这样用的:[python] view plain copylock = 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等。 所以代码修改成这样后就可以正常运行了:[python] view plain copylock = 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
- nginx -t "nginx: [warn] only the last index in "index" directive should be absolute in 6 "的问题解决
- python Synchronization between processes
- python "threads can only be started once"解决方法
- ECShop出现Strict Standards: Only variables should be
- python json转换异常:“In order to allow non-dict objects to be serialized..."
- Unity3d报告奇怪的错误CompareBaseObjectsInternal can only be called from the main thread.
- ECShop出现Strict Standards: Only variables should be passed by reference in的解决方法
- 安装Ecshop首页出现报错:Only variables should be passed by referen
- ECshop Strict Standards: Only variables should be passed by reference in
- ECshop Strict Standards: Only variables should be passed by reference in
- mysql启动异常之--TCP/IP, --shared-memory, or --named-pipe should be configured on NT OS
- ecshop报错Strict Standards: Only variables should be passed by reference in 怎么解决
- Only MySqlParameter objects may be stored
- php中出现Strict Standards: Only variables should be passed by reference in的解决方法
- 在给mysql数据库备份时,报错: mysqldump: Got error: 145: Table '.\shengdaxcom\pre_forum_thread' is marked as c rashed and should be repaired when using LOCK TABLES
- php报警:Strict Standards: Only variables should be passed by reference in