Lesson 01
Threads Overview
Learn what a Python thread is, how MainThread differs from a child thread, and why a thread is one flow of control inside a program.
Advanced25 min
Learn what a Python thread is, how MainThread differs from a child thread, and why a thread is one flow of control inside a program.
Example
import threading
print(threading.current_thread().name)
print(threading.active_count())The name is MainThread. The count is 1, because no child thread has been started. Later lessons call Thread.start(). This browser playground cannot start a second operating-system thread, so those pages run the same function on MainThread and print that fact.
Key takeaways
- A thread is a flow of control
MainThreadis the default flow, created when the program starts- A child thread runs a function or a method
- One flow is sequential; extra child flows are the thread-based style
- A thread is lighter than starting a whole new process for the same small task
- Next: Function Threads — point
Threadat a function and callstart()
Loading playground…
Check your understanding
Threads Overview Quiz
A thread in this lesson is best described as what?
1 / 10