11\section {\module {threading} ---
2- Higher-level threading interfaces. }
3- \declaremodule {standard}{threading}
2+ Higher-level threading interface }
43
5- \modulesynopsis {Higher-level threading interfaces.}
4+ \declaremodule {standard}{threading}
5+ \modulesynopsis {Higher-level threading interface.}
66
77
88This module constructs higher-level threading interfaces on top of the
@@ -85,7 +85,8 @@ \section{\module{threading} ---
8585
8686All of the methods described below are executed atomically.
8787
88- \subsection {Lock Objects }
88+
89+ \subsection {Lock Objects \label {lock-objects } }
8990
9091A primitive lock is a synchronization primitive that is not owned
9192by a particular thread when locked. In Python, it is currently
@@ -109,7 +110,7 @@ \subsection{Lock Objects}
109110
110111All methods are executed atomically.
111112
112- \begin {methoddesc }{acquire}{blocking=1 }
113+ \begin {methoddesc }{acquire}{\optional { blocking\code { = 1}} }
113114Acquire a lock, blocking or non-blocking.
114115
115116When invoked without arguments, block until the lock is
@@ -137,7 +138,8 @@ \subsection{Lock Objects}
137138There is no return value.
138139\end {methoddesc }
139140
140- \subsection {RLock Objects }
141+
142+ \subsection {RLock Objects \label {rlock-objects } }
141143
142144A reentrant lock is a synchronization primitive that may be
143145acquired multiple times by the same thread. Internally, it uses
@@ -153,7 +155,7 @@ \subsection{RLock Objects}
153155outermost pair) resets the lock to unlocked and allows another
154156thread blocked in \method {acquire()} to proceed.
155157
156- \begin {methoddesc }{acquire}{blocking=1 }
158+ \begin {methoddesc }{acquire}{\optional { blocking\code { = 1}} }
157159Acquire a lock, blocking or non-blocking.
158160
159161When invoked without arguments: if this thread already owns
@@ -189,7 +191,8 @@ \subsection{RLock Objects}
189191There is no return value.
190192\end {methoddesc }
191193
192- \subsection {Condition Objects }
194+
195+ \subsection {Condition Objects \label {condition-objects } }
193196
194197A condition variable is always associated with some kind of lock;
195198this can be passed in or one will be created by default. (Passing
@@ -248,11 +251,11 @@ \subsection{Condition Objects}
248251adding one item to the buffer only needs to wake up one consumer
249252thread.
250253
251- \begin {classdesc }{Condition}{lock=None }
252- If the \var {lock} argument is given and not \code {None}, it must be a \class {Lock}
253- or \class {RLock} object, and it is used as the underlying lock.
254- Otherwise, a new \class {RLock} object is created and used as the
255- underlying lock.
254+ \begin {classdesc }{Condition}{\optional { lock} }
255+ If the \var {lock} argument is given and not \code {None}, it must be a
256+ \class {Lock} or \class {RLock} object, and it is used as the underlying
257+ lock. Otherwise, a new \class {RLock} object is created and used as
258+ the underlying lock.
256259\end {classdesc }
257260
258261\begin {methoddesc }{acquire}{*args}
@@ -267,7 +270,7 @@ \subsection{Condition Objects}
267270lock; there is no return value.
268271\end {methoddesc }
269272
270- \begin {methoddesc }{wait}{timeout=None }
273+ \begin {methoddesc }{wait}{\optional { timeout} }
271274Wait until notified or until a timeout occurs.
272275This must only be called when the calling thread has acquired the
273276lock.
@@ -278,17 +281,17 @@ \subsection{Condition Objects}
278281timeout occurs. Once awakened or timed out, it re-acquires the lock
279282and returns.
280283
281- When the timeout argument is present and not \code {None}, it should be a
282- floating point number specifying a timeout for the operation in
283- seconds (or fractions thereof).
284+ When the \var { timeout} argument is present and not \code {None}, it
285+ should be a floating point number specifying a timeout for the
286+ operation in seconds (or fractions thereof).
284287
285- When the underlying lock is an \class {RLock}, it is not released using its
286- \method {release()} method, since this may not actually unlock the lock
287- when it was acquired multiple times recursively. Instead, an
288- internal interface of the \class {RLock} class is used, which really unlocks it
289- even when it has been recursively acquired several times. Another
290- internal interface is then used to restore the recursion level when
291- the lock is reacquired.
288+ When the underlying lock is an \class {RLock}, it is not released using
289+ its \method {release()} method, since this may not actually unlock the
290+ lock when it was acquired multiple times recursively. Instead, an
291+ internal interface of the \class {RLock} class is used, which really
292+ unlocks it even when it has been recursively acquired several times.
293+ Another internal interface is then used to restore the recursion level
294+ when the lock is reacquired.
292295\end {methoddesc }
293296
294297\begin {methoddesc }{notify}{}
@@ -314,25 +317,26 @@ \subsection{Condition Objects}
314317\method {notify()}, but wakes up all waiting threads instead of one.
315318\end {methoddesc }
316319
317- \subsection {Semaphore Objects }
320+
321+ \subsection {Semaphore Objects \label {semaphore-objects } }
318322
319323This is one of the oldest synchronization primitives in the history of
320324computer science, invented by the early Dutch computer scientist
321- Edsger W. Dijkstra (he used \method {P()} and \method {V()} instead of \method {acquire()}
322- and \method {release()}).
325+ Edsger W. Dijkstra (he used \method {P()} and \method {V()} instead of
326+ \method {acquire()} and \method {release()}).
323327
324328A semaphore manages an internal counter which is decremented by each
325329\method {acquire()} call and incremented by each \method {release()}
326330call. The counter can never go below zero; when \method {acquire()}
327331finds that it is zero, it blocks, waiting until some other thread
328332calls \method {release()}.
329333
330- \begin {classdesc }{Semaphore}{value=1 }
334+ \begin {classdesc }{Semaphore}{\optional { value} }
331335The optional argument gives the initial value for the internal
332- counter; it defaults to 1 .
336+ counter; it defaults to \code {1} .
333337\end {classdesc }
334338
335- \begin {methoddesc }{acquire}{blocking=1 }
339+ \begin {methoddesc }{acquire}{\optional { blocking} }
336340Acquire a semaphore.
337341
338342When invoked without arguments: if the internal counter is larger than
@@ -345,13 +349,13 @@ \subsection{Semaphore Objects}
345349threads are awakened should not be relied on. There is no return
346350value in this case.
347351
348- When invoked with the \var {blocking} argument set to true, do the same
349- thing as when called without arguments, and return true.
352+ When invoked with \var {blocking} set to true, do the same thing as
353+ when called without arguments, and return true.
350354
351- When invoked with the \var {blocking} argument set to false, do not
352- block. If a call without an argument would block, return false
353- immediately; otherwise, do the same thing as when called without
354- arguments, and return true.
355+ When invoked with \var {blocking} set to false, do not block. If a
356+ call without an argument would block, return false immediately;
357+ otherwise, do the same thing as when called without arguments, and
358+ return true.
355359\end {methoddesc }
356360
357361\begin {methoddesc }{release}{}
@@ -361,7 +365,8 @@ \subsection{Semaphore Objects}
361365than zero again, wake up that thread.
362366\end {methoddesc }
363367
364- \subsection {Event Objects }
368+
369+ \subsection {Event Objects \label {event-objects } }
365370
366371This is one of the simplest mechanisms for communication between
367372threads: one thread signals an event and one or more other thread
@@ -393,7 +398,7 @@ \subsection{Event Objects}
393398called to set the internal flag to true again.
394399\end {methoddesc }
395400
396- \begin {methoddesc }{wait}{timeout=None }
401+ \begin {methoddesc }{wait}{\optional { timeout} }
397402Block until the internal flag is true.
398403If the internal flag is true on entry, return immediately. Otherwise,
399404block until another thread calls \method {set()} to set the flag to
@@ -404,41 +409,42 @@ \subsection{Event Objects}
404409seconds (or fractions thereof).
405410\end {methoddesc }
406411
407- \subsection {Thread Objects }
412+
413+ \subsection {Thread Objects \label {thread-objects } }
408414
409415This class represents an activity that is run in a separate thread
410416of control. There are two ways to specify the activity: by
411417passing a callable object to the constructor, or by overriding the
412418\method {run()} method in a subclass. No other methods (except for the
413419constructor) should be overridden in a subclass. In other words,
414- \emph {only } override the \method {__init__()} and \method {run()} methods of this class.
415-
420+ \emph {only } override the \method {__init__()} and \method {run()}
421+ methods of this class.
416422
417423Once a thread object is created, its activity must be started by
418- calling the thread's \method {start()} method. This invokes the \method {run()}
419- method in a separate thread of control.
424+ calling the thread's \method {start()} method. This invokes the
425+ \method {run()} method in a separate thread of control.
420426
421427Once the thread's activity is started, the thread is considered
422428'alive' and 'active' (these concepts are almost, but not quite
423429exactly, the same; their definition is intentionally somewhat
424- vague). It stops being alive and active when its \method {run()} method
425- terminates -- either normally, or by raising an unhandled
430+ vague). It stops being alive and active when its \method {run()}
431+ method terminates -- either normally, or by raising an unhandled
426432exception. The \method {isAlive()} method tests whether the thread is
427433alive.
428434
429- Other threads can call a thread's \method {join()} method. This blocks the
430- calling thread until the thread whose \method {join()} method is called
431- is terminated.
435+ Other threads can call a thread's \method {join()} method. This blocks
436+ the calling thread until the thread whose \method {join()} method is
437+ called is terminated.
432438
433439A thread has a name. The name can be passed to the constructor,
434- set with the \method {setName()} method, and retrieved with the \method {getName()}
435- method.
440+ set with the \method {setName()} method, and retrieved with the
441+ \method {getName()} method.
436442
437443A thread can be flagged as a `` daemon thread'' . The significance
438444of this flag is that the entire Python program exits when only
439445daemon threads are left. The initial value is inherited from the
440- creating thread. The flag can be set with the \method {setDaemon()} method
441- and retrieved with the \method {getDaemon()} method.
446+ creating thread. The flag can be set with the \method {setDaemon()}
447+ method and retrieved with the \method {getDaemon()} method.
442448
443449There is a `` main thread'' object; this corresponds to the
444450initial thread of control in the Python program. It is not a
@@ -449,38 +455,37 @@ \subsection{Thread Objects}
449455threads'' . These are threads of control started outside the
450456threading module, e.g. directly from C code. Dummy thread objects
451457have limited functionality; they are always considered alive,
452- active, and daemonic, and cannot be \method {join()}ed. They are never
458+ active, and daemonic, and cannot be \method {join()}ed. They are never
453459deleted, since it is impossible to detect the termination of alien
454460threads.
455461
456462
457463\begin {classdesc }{Thread}{group=None, target=None, name=None,
458- args=(), kwargs={ }}
464+ args=(), kwargs=\{\ } }
459465This constructor should always be called with keyword
460466arguments. Arguments are:
461467
462- group
463- Should be None; reserved for future extension when a
464- ThreadGroup class is implemented.
468+ \var { group}
469+ Should be \code { None} ; reserved for future extension when a
470+ \class { ThreadGroup} class is implemented.
465471
466- target
472+ \var { target}
467473Callable object to be invoked by the \method {run()} method.
468- Defaults to None, meaning nothing is called.
474+ Defaults to \code { None} , meaning nothing is called.
469475
470- name
471- The thread name. By default, a unique name is constructed
472- of the form `` Thread-N'' where N is a small decimal
473- number.
476+ \var {name}
477+ The thread name. By default, a unique name is constructed of the form
478+ `` Thread-\var {N}'' where \var {N} is a small decimal number.
474479
475- args
476- Argument tuple for the target invocation. Defaults to () .
480+ \var { args}
481+ Argument tuple for the target invocation. Defaults to \code {()} .
477482
478- kwargs
483+ \var { kwargs}
479484Keyword argument dictionary for the target invocation.
480- Defaults to { }.
485+ Defaults to \code { \{\} }.
481486
482487If the subclass overrides the constructor, it must make sure
483- to invoke the base class constructor (Thread.__init__())
488+ to invoke the base class constructor (\code { Thread.__init__()} )
484489before doing anything else to the thread.
485490\end {classdesc }
486491
@@ -507,7 +512,7 @@ \subsection{Thread Objects}
507512\end {methoddesc }
508513
509514
510- \begin {methoddesc }{join}{timeout=None }
515+ \begin {methoddesc }{join}{\optional { timeout} }
511516Wait until the thread terminates.
512517This blocks the calling thread until the thread whose \method {join()}
513518method is called terminates -- either normally or through an
0 commit comments