DEV Community

Discussion on: Explain python global interpreter lock (GIL) Like I'm Five

Collapse
 
rhymes profile image
rhymes

If you do want to utilize more than one core, or more than one CPU for that matter, you can do so in cpython with the multiprocessing module. This can be annoying though, since it is my understanding that each process will have to run its own instance of the Python runtime. I have not used this module, so I am not sure how communication among processes is handled. Traditionally, that is supposed to be one benefit of threads over processes, that all the threads share access to the heap.

I wouldn't say it's annoying, just don't expect the overhead to be like 3kb of memory or something.

The various types of creating a process are explained here in the doc docs.python.org/3.6/library/multip... - but long story short: you can either spawn a process (a new interpreter) or clone the existing (fork). The default is the clone.

Processes can communicate through queues or pipes or they can share parts of the memory (not recommended).

Queues and pipes are implemented using unix pipe, which is not that different from what happens when in Unix you do:

cat verylongfile.txt | sort

Those two totally unrelated processes communicate through a unix pipe.