而threading 模块提供了更高级别、功能更全面的线程管理。 Threading provides higher-level, fully-featured thread management.究其原因,是因为我们只告诉threading 模块获取锁。 The reason is that we just told the threading module to acquire the lock. 程序是可以使用thread和threading 模块来创建与管理线程。 Programmers can us the thread and threading modules to create and manage threads. 一个线程可通过反复调用System.Threading . A thread can enter the semaphore multiple times by calling the System. Threading . 这里,我们导入threading 模块并且创建一个叫doubler的常规函数。 Here we import the threading module and create a regular function called doubler.
Threading 模块包括两种信号量类:Semaphore和BoundedSemaphore。The threading module comes with two semaphore classes, Semaphore and BoundedSemaphore. Multiprocessing模块还包含一些threading 模块没有的一些API。 The multiprocessing package also includes some APIs that are not in the threading module at all. 如前所述,至少threading 模块能确保重要的子线程在进程退出前结束。 As mentioned earlier, at least threading allows the important child threads to finish first before exiting. 你创建的任何多线程应用都应该使用threading 模块或其他更高级别的模块。 Any multithreaded application you create should utilize threading and perhaps other higher-level modules. 作为维护你自己的当前运行线程集合的一种替代方案,可以考虑使用threading . As an alternative to maintaining your own set of currently running threads, you might consider using threading . 上个世纪九十年代和本世纪初,他旗下公司QualityBendingandThreading 的生意很红火。 In the late 1990s and early 2000s, his company, Quality Bending and Threading , was buzzing. Threading 模块从Python1.5.2版开始出现,用于增强底层的多线程模块thread。The threading module was first introduced in Python 1.5.2 as an enhancement of the low-level thread module. 这意味着,如果你想提高代码的运行速度,使用threading 包并不是一个很好的方法。 This means that if you want to make your code run faster, then using the threading package often isn't a good idea. 对于开发者而言,最简洁的API(至少我们的意见)是继承threading . For developers, the cleanest application programming interface(API)(at least in our opinion) is to derive from threading . 我们还将展示如何使用更加合适的工具,如threading 和Queue模块中的那些方法。 We will also show you how to use more appropriate tools such as those available in the threading and Queue modules. 虽然处理这种特殊问题有很多不同的方法,不过我最喜欢的解决方案是使用threading 模块的Timer类。 While there are lots of different approaches to this particular problem, my favorite solution was using the threading module's Timer class. Python提供了几个用于多线程编程的模块,包括thread,threading 和Queue等。 Python provides several modules to support MT programming, including the thread, threading , and Queue modules. 另一个原因是低级别的thread模块拥有的同步原语很少(实际上只有一个),而threading 模块则有很多。 Another reason is that the lower-level thread module has few synchronization primitives(actually only one) while threading has many. MixedCase仅被允许用于这种风格已经占优势的上下文(如:threading .py)以便保持向后兼容. MixedCase is allowed only in contexts where that's already the prevailing style(e.g. threading . py), to retain backwards compatibility. 这些队列对象从threading 或者multiprocessing模块中而来,具体是哪个取决于你所使用的executor的实现方式。 These queue objects come from either the threading or multiprocessing module depending on which executor implementation you are using. 混合大小写(mixedCase)仅被允许用于这种风格已经占优势的上下文(如:threading .py),以便保持向后兼容。 MixedCase is allowed only in contexts where that's already the prevailing style(e.g. threading . py), to retain backwards compatibility. 不过,“freethreading ”这个补丁是有启发性意义的,其证明了一个关于Python解释器的基本要点:移除GIL是非常困难的。 The"free threading " patches are instructive, though, in that they demonstrate a fundamental point about the Python interpreter: removing the GIL is hard. 线程通过调用从WaitHandle类中继承的WaitOne方法进入信号量,无论对于System.Threading . Threads enter the semaphore by calling the WaitOne method, which is inherited from the WaitHandle class, in the case of a System. Threading . 许多人也许不知道,在1999年,针对Python1.5,一个经常被提到但却不怎么理解的“freethreading ”补丁已经尝试实现了这个想法,该补丁来自GregStein。 Many are not aware, but this was attempted back in 1999 for Python 1.5 in the oft-cited but poorly understood"free threading " patches from Greg Stein. ApolloOne采用先进的操作系统功能,如multi-threading ,GrandCentralDispatch和CoreImage图像引擎,以确保应用程序有快速的反应能力. ApolloOne uses advanced Operating System features such as multi-threading , Grand Central Dispatch, and Core Image graphics to ensure app responsiveness. 那么为什么不抛弃GIL呢?许多人也许不知道,在1999年,针对Python1.5,一个经常被提到但却不怎么理解的“freethreading ”补丁已经尝试实现了这个想法,该补丁来自GregStein。 Many are not aware, but this was attempted back in 1999 for Python 1.5 in the oft-cited but poorly understood"free threading " patches from Greg Stein. DeanTullsen的成果也被用于开发英特尔奔腾4微处理器的超线程技术(Hyper-threading ,或称HTT)的版本,例如“Northwood”和“Prescott”。 Dean Tullsen's work was also used to develop the Hyper-threading (Hyper-threading technology or HTT) versions of the Intel Pentium 4 microprocessors, such as the"Northwood" and"Prescott".
Display more examples
Results: 27 ,
Time: 0.0247