...

/

Puzzle 24: Explanation

Puzzle 24: Explanation

Let’s find out how threads and processes work in Python.

We'll cover the following...

Try it yourself

Try executing the code below to verify the results:

Press + to interact
from concurrent.futures import ProcessPoolExecutor
from itertools import repeat
guilty = 0
def juror():
global guilty
guilty += 1
with ProcessPoolExecutor() as pool:
for _ in repeat(None, 12):
pool.submit(juror)
print(guilty)

Explanation

Both threads and processes are concurrent units of work. The main difference is that threads share the same memory space and processes don’t. This means that if we have a global variable (like guilty ...