This class represents an activity that is run in a separate thread of control.
There are two ways to specify the activity: by passing a callable object to the
- constructor, or by overriding the :meth:`run` method in a subclass. No other
- methods (except for the constructor) should be overridden in a subclass. In
- other words, *only* override the :meth:`__init__` and :meth:`run` methods of
- this class.
+ constructor, or by overriding the :meth:`~Thread.run` method in a subclass.
+ No other methods (except for the constructor) should be overridden in a
+ subclass. In other words, *only* override the :meth:`~Thread.__init__`
+ and :meth:`~Thread.run` methods of this class.
Once a thread object is created, its activity must be started by calling the
- thread's :meth:`start` method. This invokes the :meth:`run` method in a
- separate thread of control.
+ thread's :meth:`~Thread.start` method. This invokes the :meth:`~Thread.run`
+ method in a separate thread of control.
Once the thread's activity is started, the thread is considered 'alive'. It
- stops being alive when its :meth:`run` method terminates -- either normally, or
- by raising an unhandled exception. The :meth:`is_alive` method tests whether the
- thread is alive.
+ stops being alive when its :meth:`~Thread.run` method terminates -- either
+ normally, or by raising an unhandled exception. The :meth:`~Thread.is_alive`
+ method tests whether the thread is alive.
- Other threads can call a thread's :meth:`join` method. This blocks the calling
- thread until the thread whose :meth:`join` method is called is terminated.
+ Other threads can call a thread's :meth:`~Thread.join` method. This blocks
+ the calling thread until the thread whose :meth:`~Thread.join` method is
+ called is terminated.
A thread has a name. The name can be passed to the constructor, and read or
- changed through the :attr:`name` attribute.
+ changed through the :attr:`~Thread.name` attribute.
-A thread can be flagged as a "daemon thread". The significance of this flag
-is that the entire Python program exits when only daemon threads are left.
-The initial value is inherited from the creating thread. The flag can be
-set through the :attr:`~Thread.daemon` property.
+A thread can be flagged as a "daemon thread". The significance of this flag is
+that the entire Python program exits when only daemon threads are left. The
+initial value is inherited from the creating thread. The flag can be set
- through the :attr:`daemon` property or the *daemon* constructor argument.
++through the :attr:`~Thread.daemon` property or the *daemon* constructor
++argument.
There is a "main thread" object; this corresponds to the initial thread of
control in the Python program. It is not a daemon thread.
thread objects corresponding to "alien threads", which are threads of control
started outside the threading module, such as directly from C code. Dummy
thread objects have limited functionality; they are always considered alive and
- daemonic, and cannot be :meth:`join`\ ed. They are never deleted, since it is
- impossible to detect the termination of alien threads.
+ daemonic, and cannot be :meth:`~Thread.join`\ ed. They are never deleted,
+ since it is impossible to detect the termination of alien threads.
-.. class:: Thread(group=None, target=None, name=None, args=(), kwargs={})
+.. class:: Thread(group=None, target=None, name=None, args=(), kwargs={},
+ verbose=None, *, daemon=None)
This constructor should always be called with keyword arguments. Arguments
are: