Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does python os.fork uses the same python interpreter?

I understand that threads in Python use the same instance of Python interpreter. My question is it the same with process created by os.fork? Or does each process created by os.fork has its own interpreter?

like image 946
Ezra Avatar asked May 11 '15 00:05

Ezra


1 Answers

Whenever you fork, the entire Python process is duplicated in memory (including the Python interpreter, your code and any libraries, current stack etc.) to create a second process - one reason why forking a process is much more expensive than creating a thread.

This creates a new copy of the python interpreter.

One advantage of having two python interpreters running is that you now have two GIL's (Global Interpreter Locks), and therefore can have true multi-processing on a multi-core system.

Threads in one process share the same GIL, meaning only one runs at a given moment, giving only the illusion of parallelism.

like image 50
14 revs, 12 users 16% Avatar answered Sep 26 '22 08:09

14 revs, 12 users 16%