Python Global Interpreter Lock
https://realpython.com/python-gil/
What is GIL?
Why do we need it in Python?
>>> import sys
>>> a = []
>>> b = a
>>> sys.getrefcount(a)
3The impact on multi-threaded Python programs
# single_threaded.py
import time
from threading import Thread
COUNT = 100000000
def countdown(n):
while n>0:
n -= 1
start = time.time()
countdown(COUNT)
end = time.time()
print('Time taken in seconds -', end - start) # Took 6.608175992965698 on my MacHow to deal with Python’s GIL
Last updated