Skip to main content
MahiDev — Learn. Build. Become AI-ready.

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
Threads overview hero Module 19 Lesson 1 MainThread and a child flow

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.

The path through this module

Example

python
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
  • MainThread is 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 Thread at a function and call start()

Loading playground…

Check your understanding

Threads Overview Quiz

A thread in this lesson is best described as what?

1 / 10