Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Concurrency with threading | Python Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Python Fundamentals

Lesson 43 of 55

·Python

Concurrency with threading

20 minutes

Course progress78%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • Create a thread with `threading.Thread(target=func, args=())`.
  • Start with `thread.start()`, wait with `thread.join()`.
  • `threading` shares memory, so protect shared data with locks (`threading.Lock`).
  • Ideal for I/O‑bound workloads due to the GIL.

Concurrency with threading

The threading module lets you run multiple threads in the same process, which is handy for I/O‑bound tasks such as network requests or file operations.

import threading
import time

def worker(name):
    print(f'Thread {name} starting')
    time.sleep(2)
    print(f'Thread {name} finished')

threads = []
for i in range(3):
    t = threading.Thread(target=worker, args=(i,))
    threads.append(t)
    t.start()

# Wait for all threads to finish
for t in threads:
    t.join()

print('All threads completed')

Because of the Global Interpreter Lock (GIL), threading is best suited for I/O‑bound work; for CPU‑heavy tasks you’ll want multiprocessing.

Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Python FundamentalsBrowse activities
Previous lessonAsyncIO BasicsContinue to lesson 44MultiprocessingBack to Python Fundamentals curriculum