GIL

What is GIL

Global interpreter lock.

  • ensuring a single threaded operation in Python.

The GIL does not have much impact on the performance of I/O-bound multi-threaded programs as the lock is shared between threads while they are waiting for I/O.

Instead, a multi-processing may increase performance.

  • Each Python process gets its own Python interpreter and memory space so the GIL won’t be a problem.
# multi-thread from threading import Thread t1 = Thread(target=countdown, args=(COUNT//2,)) t2 = Thread(target=countdown, args=(COUNT//2,)) # multi-process from multiprocessing import Pool if __name__ == '__main__': pool = Pool(processes=2)