PyDocs

Nav

Concurrent Execution

Thread

threading

class (source) not WASI
  • Thread(group=None, target=None, name=None, args=(), kwargs={}, *, daemon=None, context=None)
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.
Changed in 3.3, 3.10, 3.14
  • 3.3: Added the daemon parameter.
  • 3.10: Use the target name if name argument is omitted.
  • 3.14: Added the context parameter.
Members of Thread

d

daemon
A boolean value indicating whether this thread is a daemon thread.

g

getName
Return a string used for identification purposes only.

i

ident
Thread identifier of this thread or None if it has not been started.
is_alive
Return whether the thread is alive.
isDaemon
Return whether this thread is a daemon.

j

join
Wait until the thread terminates.

n

name
A string used for identification purposes only.
native_id
Native integral thread ID of this thread, or None if it has not been started.

r

run
Method representing the thread's activity.

s

setDaemon
Set whether this thread is a daemon.
setName
Set the name string for this thread.
start
Start the thread's activity.
1 Example
>>> log = []
>>> def f():
...     items = sorted(mydata.__dict__.items())
...     log.append(items)
...     mydata.number = 11
...     log.append(mydata.number)

>>> import threading
>>> thread = threading.Thread(target=f)
>>> thread.start()
>>> thread.join()
>>> log
[[], 11]
from the Python docs
See Also
No see-alsos for threading/Thread
0 Notes
No notes for Thread