- Mastering Concurrency in Python
- Quan Nguyen
- 210字
- 2021-06-10 19:24:02
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.
- HTML5+CSS3+JavaScript從入門到精通:上冊(微課精編版·第2版)
- SEO智慧
- Mastering Scientific Computing with R
- Python高效開發實戰:Django、Tornado、Flask、Twisted(第3版)
- Getting Started with LLVM Core Libraries
- 51單片機C語言開發教程
- Python程序設計與算法基礎教程(第2版)(微課版)
- Django 3.0入門與實踐
- Cocos2d-x Game Development Blueprints
- OpenCV 3 Blueprints
- Struts 2.x權威指南
- Learning Ionic
- 零基礎學HTML+CSS
- Julia數據科學應用
- Appcelerator Titanium:Patterns and Best Practices