From the course: Complete Guide to Parallel and Concurrent Programming in Python
Unlock the full course today
Join today to access over 24,900 courses taught by industry experts.
Global interpreter lock: Python demo - Python Tutorial
From the course: Complete Guide to Parallel and Concurrent Programming in Python
Global interpreter lock: Python demo
- [Instructor] Using threads to handle concurrent tasks in Python is fairly straightforward. However, the Python interpreter will not allow those concurrent threads to execute simultaneously in parallel due to a mechanism called the Global Interpreter Lock or GIL. It's something that's unique to Python and important to address upfront. The GIL is a mechanism in Python that prevents multiple Python threads from executing at the same time. That means if your program is written to have 10 concurrent threads, only one of them can execute at a time, while the other nine wait their turn. This may seem like an odd limitation, but remember that, under the hood, your Python program is actually being executed by a program called an interpreter. The interpreter compiles your Python program into an intermediate byte code, which is then executed with a virtual machine along with any necessary modules from the library. The default and by far most widely used interpreter is CPython, and as its name…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Thread vs. process4m 35s
-
(Locked)
Concurrent vs. parallel execution4m 53s
-
(Locked)
Global interpreter lock: Python demo4m 35s
-
(Locked)
Multiple threads: Python demo5m 52s
-
(Locked)
Multiple processes: Python demo5m 42s
-
(Locked)
Execution scheduling3m 38s
-
(Locked)
Execution scheduling: Python demo2m 42s
-
(Locked)
Thread lifecycle3m 35s
-
(Locked)
Thread lifecycle: Python demo5m 38s
-
(Locked)
Daemon thread2m 48s
-
(Locked)
Daemon thread: Python demo2m 29s
-
-
-
-
-
-
-
-
-
-
-