This constructor should always be called with keyword arguments. Arguments are: *group* should be None; reserved for future extension when a ThreadGroup class is implemented. *target* is the callable object to be invoked by the run() method. Defaults to None, meanin
(self, group=None, target=None, name=None,
args=(), kwargs=None, *, daemon=None, context=None)
| 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 |
| 920 | self._args = args |
| 921 | self._kwargs = kwargs |
| 922 | if daemon is not None: |
| 923 | if daemon and not _daemon_threads_allowed(): |
| 924 | raise RuntimeError('daemon threads are disabled in this (sub)interpreter') |
| 925 | self._daemonic = daemon |
| 926 | else: |
| 927 | self._daemonic = current_thread().daemon |
| 928 | self._context = context |
| 929 | self._ident = None |
| 930 | if _HAVE_THREAD_NATIVE_ID: |
nothing calls this directly
no test coverage detected