官术网_书友最值得收藏!

The thread module in Python 2

Before the threading module became popular, the primary thread-based development module was thread. If you are using an older version of Python 2, it is possible to use the module as it is. However, according to the module documentation page, the thread module was, in fact, renamed _thread in Python 3.

For readers that have been working with the thread module to build multithreaded applications and are looking to port their code from Python 2 to Python 3, the 2to3 tool might be a solution. The 2to3 tool handles most of the detectable incompatibilities between the different versions of Python, while parsing the source and traversing the source tree to convert Python 2.x code into Python 3.x code. Another trick to achieve the conversion is to change the import code from import thread to import _thread as thread in your Python programs.

The main feature of the thread module is its fast and sufficient method of creating new threads to execute functions: the thread.start_new_thread() function. Aside from this, the module only supports a number of low-level ways to work with multithreaded primitives and share their global data space. Additionally, simple lock objects (for example, mutexes and semaphores) are provided for synchronization purposes.

主站蜘蛛池模板: 静安区| 建平县| 金川县| 远安县| 定边县| 井冈山市| 常山县| 元江| 五原县| 蒙山县| 延边| 财经| 翼城县| 长垣县| 万山特区| 安新县| 泰来县| 大田县| 会昌县| 南靖县| 普兰店市| 张家口市| 博湖县| 牡丹江市| 同江市| 视频| 绵阳市| 正阳县| 苗栗县| 淳安县| 萨迦县| 柘荣县| 鄂温| 嵊泗县| 思茅市| 墨玉县| 于都县| 日喀则市| 甘德县| 大洼县| 乐安县|