Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:7.4 threadUp:7. Optional Operating SystemNext:7.5.1 Lock Objects

7.5threading -- Higher-level threading interface

This module constructs higher-level threading interfaces on top of the lower levelthread module.

This module defines the following functions and objects:

activeCount()
Return the number of currently activeThread objects.The returned count is equal to the length of the list returned byenumerate().A function that returns the number of currently active threads.

Condition()
A factory function that returns a new condition variable object.A condition variable allows one or more threads to wait until theyare notified by another thread.

currentThread()
Return the currentThread object, corresponding to thecaller's thread of control. If the caller's thread of control was notcreated through thethreading module, a dummy thread object with limited functionalityis returned.

enumerate()
Return a list of all currently activeThread objects.The list includes daemonic threads, dummy thread objects createdbycurrentThread(), and the main thread. It excludes terminatedthreads and threads that have not yet been started.

Event()
A factory function that returns a new event object. An event managesa flag that can be set to true with theset() method andreset to false with theclear() method. Thewait()method blocks until the flag is true.

Lock()
A factory function that returns a new primitive lock object. Oncea thread has acquired it, subsequent attempts to acquire it block,until it is released; any thread may release it.

RLock()
A factory function that returns a new reentrant lock object.A reentrant lock must be released by the thread that acquired it.Once a thread has acquired a reentrant lock, the same thread mayacquire it again without blocking; the thread must release it oncefor each time it has acquired it.

Semaphore([value])
A factory function that returns a new semaphore object. Asemaphore manages a counter representing the number ofrelease()calls minus the number ofacquire() calls, plus an initial value.Theacquire() method blocks if necessary until it can returnwithout making the counter negative. If not given,value defaults to1.

BoundedSemaphore([value])
A factory function that returns a new bounded semaphore object. A boundedsemaphore checks to make sure its current value doesn't exceed its initialvalue. If it does,ValueError is raised. In most situationssemaphores are used to guard resources with limited capacity. If thesemaphore is released too many times it's a sign of a bug. If not given,value defaults to 1.

classThread
A class that represents a thread of control. This class can be safelysubclassed in a limited fashion.

classTimer
A thread that executes a function after a specified interval has passed.

Detailed interfaces for the objects are documented below.

The design of this module is loosely based on Java's threading model.However, where Java makes locks and condition variables basic behaviorof every object, they are separate objects in Python. Python'sThreadclass supports a subset of the behavior of Java's Thread class;currently, there are no priorities, no thread groups, and threadscannot be destroyed, stopped, suspended, resumed, or interrupted. Thestatic methods of Java's Thread class, when implemented, are mapped tomodule-level functions.

All of the methods described below are executed atomically.


Subsections


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:7.4 threadUp:7. Optional Operating SystemNext:7.5.1 Lock Objects
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp