MCPcopy Index your code
hub / github.com/python/cpython / Thread

Class Thread

Lib/threading.py:862–1248  ·  view source on GitHub ↗

A class that represents a thread of control. This class can be safely subclassed in a limited fashion. There are two ways to specify the activity: by passing a callable object to the constructor, or by overriding the run() method in a subclass.

Source from the content-addressed store, hash-verified

860# Main class for threads
861
862class Thread:
863 """A class that represents a thread of control.
864
865 This class can be safely subclassed in a limited fashion. There are two ways
866 to specify the activity: by passing a callable object to the constructor, or
867 by overriding the run() method in a subclass.
868
869 """
870
871 _initialized = False
872
873 def __init__(self, group=None, target=None, name=None,
874 args=(), kwargs=None, *, daemon=None, context=None):
875 """This constructor should always be called with keyword arguments. Arguments are:
876
877 *group* should be None; reserved for future extension when a ThreadGroup
878 class is implemented.
879
880 *target* is the callable object to be invoked by the run()
881 method. Defaults to None, meaning nothing is called.
882
883 *name* is the thread name. By default, a unique name is constructed of
884 the form "Thread-N" where N is a small decimal number.
885
886 *args* is a list or tuple of arguments for the target invocation. Defaults to ().
887
888 *kwargs* is a dictionary of keyword arguments for the target
889 invocation. Defaults to {}.
890
891 *context* is the contextvars.Context value to use for the thread.
892 The default value is None, which means to check
893 sys.flags.thread_inherit_context. If that flag is true, use a copy
894 of the context of the caller. If false, use an empty context. To
895 explicitly start with an empty context, pass a new instance of
896 contextvars.Context(). To explicitly start with a copy of the current
897 context, pass the value from contextvars.copy_context().
898
899 If a subclass overrides the constructor, it must make sure to invoke
900 the base class constructor (Thread.__init__()) before doing anything
901 else to the thread.
902
903 """
904 assert group is None, "group argument must be None for now"
905 if kwargs is None:
906 kwargs = {}
907 if name:
908 name = str(name)
909 else:
910 name = _newname("Thread-%d")
911 if target is not None:
912 try:
913 target_name = target.__name__
914 name += f" ({target_name})"
915 except AttributeError:
916 pass
917
918 self._target = target
919 self._name = name

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…