且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在多线程程序中同步嵌入式 Python

更新时间:2022-05-16 21:10:08

with 声明有 问题在 Python 3.1 中,但在 Python 3.2 和 Python 2.7 中已修复.

with statement has issue in Python 3.1, but it was fixed in Python 3.2 and Python 2.7.

所以正确的解决方案是使用threading模块进行同步.

So the right solution is to use the threading module for synchronization.

为避免此类问题,不应使用在全局字典中使用临时变量的多线程代码,或为每个线程使用不同的全局字典.

To avoid such issues, one shouldn't use multi-threaded code which uses temporary variables in globals dictionary, or use different globals dictionaries for each thread.