DEV Community

Discussion on: Multithreading vs Multiprocessing in Python 🐍

Collapse
 
jacopobonta profile image
Jacopo

In an attempt to see the differences between processes and threads I tried to add the result variable also to the first example. Since with thread we share the same memory heap i was expected to see print(result) outputting the square result. Instead like the example with the multiprocesses None was printed, can you or someone else explain me why this happens?

Collapse
 
mdah profile image
m-dah

Declare the "result" variable as global in main and threads so it does not create a new local variable for each thread.