February 2019
Intermediate to advanced
672 pages
16h 50m
English
Intuitively, with a lock guarding all CPU-bound tasks in Python, a concurrent program will not be able to become fully multithreading. The GIL effectively prevents CPU-bound tasks from being executed in parallel across multiple threads. To understand the effect of this feature of the GIL, let's consider an example in Python; navigate to Chapter22/example2.py, as follows:
# Chapter22/example2.pyimport timeimport threadingCOUNT = 50000000def countdown(n): while n > 0: n -= 1###########################################################################start = time.time()countdown(COUNT)print('Sequential program finished.')print(f'Took {time.time() - start : .2f} seconds.')########################################################################### ...