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

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.

主站蜘蛛池模板: 广元市| 阿鲁科尔沁旗| 星座| 伊金霍洛旗| 宜兴市| 安达市| 额敏县| 远安县| 海城市| 措美县| 汉川市| 华蓥市| 舞钢市| 辽宁省| 德兴市| 宜川县| 济源市| 大厂| 溧阳市| 清流县| 申扎县| 绥芬河市| 交城县| 卢氏县| 白河县| 克拉玛依市| 隆子县| 江川县| 黎平县| 渭南市| 玉树县| 柞水县| 长寿区| 永昌县| 荆门市| 天台县| 任丘市| 文登市| 广昌县| 永平县| 兴国县|