@@ -218,30 +218,31 @@ Thread Objects
218218
219219This class represents an activity that is run in a separate thread of control.
220220There are two ways to specify the activity: by passing a callable object to the
221- constructor, or by overriding the :meth: `run ` method in a subclass. No other
222- methods (except for the constructor) should be overridden in a subclass. In
223- other words, *only * override the :meth: `__init__ ` and :meth: ` run ` methods of
224- this class.
221+ constructor, or by overriding the :meth: `~Thread. run ` method in a subclass.
222+ No other methods (except for the constructor) should be overridden in a
223+ subclass. In other words, *only * override the :meth: `~Thread. __init__ `
224+ and :meth: ` ~Thread.run ` methods of this class.
225225
226226Once a thread object is created, its activity must be started by calling the
227- thread's :meth: `start ` method. This invokes the :meth: `run ` method in a
228- separate thread of control.
227+ thread's :meth: `~Thread. start ` method. This invokes the :meth: `~Thread. run `
228+ method in a separate thread of control.
229229
230230Once the thread's activity is started, the thread is considered 'alive'. It
231- stops being alive when its :meth: `run ` method terminates -- either normally, or
232- by raising an unhandled exception. The :meth: `is_alive ` method tests whether the
233- thread is alive.
231+ stops being alive when its :meth: `~Thread. run ` method terminates -- either
232+ normally, or by raising an unhandled exception. The :meth: `~Thread. is_alive `
233+ method tests whether the thread is alive.
234234
235- Other threads can call a thread's :meth: `join ` method. This blocks the calling
236- thread until the thread whose :meth: `join ` method is called is terminated.
235+ Other threads can call a thread's :meth: `~Thread.join ` method. This blocks
236+ the calling thread until the thread whose :meth: `~Thread.join ` method is
237+ called is terminated.
237238
238239A thread has a name. The name can be passed to the constructor, and read or
239- changed through the :attr: `name ` attribute.
240+ changed through the :attr: `~Thread. name ` attribute.
240241
241- A thread can be flagged as a "daemon thread". The significance of this flag is
242- that the entire Python program exits when only daemon threads are left. The
243- initial value is inherited from the creating thread. The flag can be set
244- through the :attr: `daemon ` property.
242+ A thread can be flagged as a "daemon thread". The significance of this flag
243+ is that the entire Python program exits when only daemon threads are left.
244+ The initial value is inherited from the creating thread. The flag can be
245+ set through the :attr: `~Thread. daemon ` property.
245246
246247There is a "main thread" object; this corresponds to the initial thread of
247248control in the Python program. It is not a daemon thread.
@@ -250,8 +251,8 @@ There is the possibility that "dummy thread objects" are created. These are
250251thread objects corresponding to "alien threads", which are threads of control
251252started outside the threading module, such as directly from C code. Dummy
252253thread objects have limited functionality; they are always considered alive and
253- daemonic, and cannot be :meth: `join `\ ed. They are never deleted, since it is
254- impossible to detect the termination of alien threads.
254+ daemonic, and cannot be :meth: `~Thread. join `\ ed. They are never deleted,
255+ since it is impossible to detect the termination of alien threads.
255256
256257
257258.. class :: Thread(group=None, target=None, name=None, args=(), kwargs={})
@@ -282,7 +283,8 @@ impossible to detect the termination of alien threads.
282283 Start the thread's activity.
283284
284285 It must be called at most once per thread object. It arranges for the
285- object's :meth: `run ` method to be invoked in a separate thread of control.
286+ object's :meth: `~Thread.run ` method to be invoked in a separate thread
287+ of control.
286288
287289 This method will raise a :exc: `RuntimeError ` if called more than once
288290 on the same thread object.
@@ -298,25 +300,27 @@ impossible to detect the termination of alien threads.
298300
299301 .. method :: join(timeout=None)
300302
301- Wait until the thread terminates. This blocks the calling thread until the
302- thread whose :meth: `join ` method is called terminates -- either normally
303- or through an unhandled exception -- or until the optional timeout occurs.
303+ Wait until the thread terminates. This blocks the calling thread until
304+ the thread whose :meth: `~Thread.join ` method is called terminates -- either
305+ normally or through an unhandled exception --, or until the optional
306+ timeout occurs.
304307
305308 When the *timeout * argument is present and not ``None ``, it should be a
306309 floating point number specifying a timeout for the operation in seconds
307- (or fractions thereof). As :meth: `join ` always returns ``None ``, you must
308- call :meth: `is_alive ` after :meth: `join ` to decide whether a timeout
309- happened -- if the thread is still alive, the :meth: `join ` call timed out.
310+ (or fractions thereof). As :meth: `~Thread.join ` always returns ``None ``,
311+ you must call :meth: `~Thread.is_alive ` after :meth: `~Thread.join ` to
312+ decide whether a timeout happened -- if the thread is still alive, the
313+ :meth: `~Thread.join ` call timed out.
310314
311315 When the *timeout * argument is not present or ``None ``, the operation will
312316 block until the thread terminates.
313317
314- A thread can be :meth: `join `\ ed many times.
318+ A thread can be :meth: `~Thread. join `\ ed many times.
315319
316- :meth: `join ` raises a :exc: `RuntimeError ` if an attempt is made to join
317- the current thread as that would cause a deadlock. It is also an error to
318- :meth: `join ` a thread before it has been started and attempts to do so
319- raises the same exception.
320+ :meth: `~Thread. join ` raises a :exc: `RuntimeError ` if an attempt is made
321+ to join the current thread as that would cause a deadlock. It is also
322+ an error to :meth: `~Thread. join ` a thread before it has been started
323+ and attempts to do so raise the same exception.
320324
321325 .. attribute :: name
322326
@@ -334,26 +338,26 @@ impossible to detect the termination of alien threads.
334338
335339 The 'thread identifier' of this thread or ``None `` if the thread has not
336340 been started. This is a nonzero integer. See the
337- :func: `thread .get_ident() ` function. Thread identifiers may be recycled
341+ :func: `_thread .get_ident() ` function. Thread identifiers may be recycled
338342 when a thread exits and another thread is created. The identifier is
339343 available even after the thread has exited.
340344
341345 .. method :: is_alive()
342346
343347 Return whether the thread is alive.
344348
345- This method returns ``True `` just before the :meth: `run ` method starts
346- until just after the :meth: `run ` method terminates. The module function
347- :func: `.enumerate ` returns a list of all alive threads.
349+ This method returns ``True `` just before the :meth: `~Thread. run ` method
350+ starts until just after the :meth: `~Thread. run ` method terminates. The
351+ module function :func: `.enumerate ` returns a list of all alive threads.
348352
349353 .. attribute :: daemon
350354
351355 A boolean value indicating whether this thread is a daemon thread (True)
352- or not (False). This must be set before :meth: `start ` is called,
356+ or not (False). This must be set before :meth: `~Thread. start ` is called,
353357 otherwise :exc: `RuntimeError ` is raised. Its initial value is inherited
354358 from the creating thread; the main thread is not a daemon thread and
355- therefore all threads created in the main thread default to :attr: ` daemon `
356- = ``False ``.
359+ therefore all threads created in the main thread default to
360+ :attr: ` ~Thread.daemon ` = ``False ``.
357361
358362 The entire Python program exits when no alive non-daemon threads are left.
359363
@@ -375,19 +379,20 @@ synchronization primitive available, implemented directly by the :mod:`_thread`
375379extension module.
376380
377381A primitive lock is in one of two states, "locked" or "unlocked". It is created
378- in the unlocked state. It has two basic methods, :meth: `acquire ` and
379- :meth: `release `. When the state is unlocked, :meth: `acquire ` changes the state
380- to locked and returns immediately. When the state is locked, :meth: `acquire `
381- blocks until a call to :meth: `release ` in another thread changes it to unlocked,
382- then the :meth: `acquire ` call resets it to locked and returns. The
383- :meth: `release ` method should only be called in the locked state; it changes the
384- state to unlocked and returns immediately. If an attempt is made to release an
385- unlocked lock, a :exc: `RuntimeError ` will be raised.
386-
387- When more than one thread is blocked in :meth: `acquire ` waiting for the state to
388- turn to unlocked, only one thread proceeds when a :meth: `release ` call resets
389- the state to unlocked; which one of the waiting threads proceeds is not defined,
390- and may vary across implementations.
382+ in the unlocked state. It has two basic methods, :meth: `~Lock.acquire ` and
383+ :meth: `~Lock.release `. When the state is unlocked, :meth: `~Lock.acquire `
384+ changes the state to locked and returns immediately. When the state is locked,
385+ :meth: `~Lock.acquire ` blocks until a call to :meth: `~Lock.release ` in another
386+ thread changes it to unlocked, then the :meth: `~Lock.acquire ` call resets it
387+ to locked and returns. The :meth: `~Lock.release ` method should only be
388+ called in the locked state; it changes the state to unlocked and returns
389+ immediately. If an attempt is made to release an unlocked lock, a
390+ :exc: `RuntimeError ` will be raised.
391+
392+ When more than one thread is blocked in :meth: `~Lock.acquire ` waiting for the
393+ state to turn to unlocked, only one thread proceeds when a :meth: `~Lock.release `
394+ call resets the state to unlocked; which one of the waiting threads proceeds
395+ is not defined, and may vary across implementations.
391396
392397All methods are executed atomically.
393398
@@ -446,12 +451,12 @@ and "recursion level" in addition to the locked/unlocked state used by primitive
446451locks. In the locked state, some thread owns the lock; in the unlocked state,
447452no thread owns it.
448453
449- To lock the lock, a thread calls its :meth: `acquire ` method; this returns once
450- the thread owns the lock. To unlock the lock, a thread calls its
451- :meth: `release ` method. :meth: `acquire `/:meth: `release ` call pairs may be
452- nested; only the final :meth: `release ` (the :meth: ` release ` of the outermost
453- pair) resets the lock to unlocked and allows another thread blocked in
454- :meth: `acquire ` to proceed.
454+ To lock the lock, a thread calls its :meth: `~RLock. acquire ` method; this
455+ returns once the thread owns the lock. To unlock the lock, a thread calls
456+ its :meth: `~Lock. release ` method. :meth: `~Lock. acquire `/:meth: `~Lock. release `
457+ call pairs may be nested; only the final :meth: `~Lock. release ` (the
458+ :meth: ` ~Lock.release ` of the outermost pair) resets the lock to unlocked and
459+ allows another thread blocked in :meth: `~Lock. acquire ` to proceed.
455460
456461
457462.. method :: RLock.acquire(blocking=True, timeout=-1)
@@ -672,12 +677,14 @@ Semaphore Objects
672677
673678This is one of the oldest synchronization primitives in the history of computer
674679science, invented by the early Dutch computer scientist Edsger W. Dijkstra (he
675- used :meth: `P ` and :meth: `V ` instead of :meth: `acquire ` and :meth: `release `).
680+ used the names ``P() `` and ``V() `` instead of :meth: `~Semaphore.acquire ` and
681+ :meth: `~Semaphore.release `).
676682
677683A semaphore manages an internal counter which is decremented by each
678- :meth: `acquire ` call and incremented by each :meth: `release ` call. The counter
679- can never go below zero; when :meth: `acquire ` finds that it is zero, it blocks,
680- waiting until some other thread calls :meth: `release `.
684+ :meth: `~Semaphore.acquire ` call and incremented by each :meth: `~Semaphore.release `
685+ call. The counter can never go below zero; when :meth: `~Semaphore.acquire `
686+ finds that it is zero, it blocks, waiting until some other thread calls
687+ :meth: `~Semaphore.release `.
681688
682689
683690.. class :: Semaphore(value=1)
@@ -693,11 +700,12 @@ waiting until some other thread calls :meth:`release`.
693700 When invoked without arguments: if the internal counter is larger than
694701 zero on entry, decrement it by one and return immediately. If it is zero
695702 on entry, block, waiting until some other thread has called
696- :meth: `release ` to make it larger than zero. This is done with proper
697- interlocking so that if multiple :meth: `acquire ` calls are blocked,
698- :meth: `release ` will wake exactly one of them up. The implementation may
699- pick one at random, so the order in which blocked threads are awakened
700- should not be relied on. Returns true (or blocks indefinitely).
703+ :meth: `~Semaphore.release ` to make it larger than zero. This is done
704+ with proper interlocking so that if multiple :meth: `acquire ` calls are
705+ blocked, :meth: `~Semaphore.release ` will wake exactly one of them up.
706+ The implementation may pick one at random, so the order in which
707+ blocked threads are awakened should not be relied on. Returns
708+ true (or blocks indefinitely).
701709
702710 When invoked with *blocking * set to false, do not block. If a call
703711 without an argument would block, return false immediately; otherwise,
@@ -753,8 +761,8 @@ This is one of the simplest mechanisms for communication between threads: one
753761thread signals an event and other threads wait for it.
754762
755763An event object manages an internal flag that can be set to true with the
756- :meth: `~Event.set ` method and reset to false with the :meth: `clear ` method. The
757- :meth: `wait ` method blocks until the flag is true.
764+ :meth: `~Event.set ` method and reset to false with the :meth: `~Event. clear `
765+ method. The :meth: `~Event. wait ` method blocks until the flag is true.
758766
759767
760768.. class :: Event()
@@ -781,7 +789,7 @@ An event object manages an internal flag that can be set to true with the
781789
782790 Block until the internal flag is true. If the internal flag is true on
783791 entry, return immediately. Otherwise, block until another thread calls
784- :meth: `set ` to set the flag to true, or until the optional timeout occurs.
792+ :meth: `. set ` to set the flag to true, or until the optional timeout occurs.
785793
786794 When the timeout argument is present and not ``None ``, it should be a
787795 floating point number specifying a timeout for the operation in seconds
@@ -837,8 +845,8 @@ Barrier Objects
837845
838846This class provides a simple synchronization primitive for use by a fixed number
839847of threads that need to wait for each other. Each of the threads tries to pass
840- the barrier by calling the :meth: `wait ` method and will block until all of the
841- threads have made the call. At this points, the threads are released
848+ the barrier by calling the :meth: `~Barrier. wait ` method and will block until
849+ all of the threads have made the call. At this points, the threads are released
842850simultanously.
843851
844852The barrier can be reused any number of times for the same number of threads.
0 commit comments