The Global Interpreter Lock (GIL) is a mutex in Python. It prevents multiple native threads from executing Python bytecodes simultaneously. This means that even in multi-threaded programs, only one thread can execute Python code at a time.
Implications of GIL include limitations in CPU-bound multi-threaded applications. However, I/O-bound applications are less affected by GIL.
Example of GIL impact:
import threading
def task():
print('Task executed')
threads = [threading.Thread(target=task) for _ in range(10)]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
Leave a Reply