Python shared libraries

As I understand it, in python (CPython) there are two types of modules: - extension .so (C) -.py

.so are loaded only once, even when there are different processes / interpreters importing them.

.py is loaded once for each process / interpreter (unless explicitly loaded).

Is there a way .py can be used by multiple processes / interpreters?

Someone will need another layer where you can save the changes made to the module. I think you can embed an interpreter in .so as a first step. Is there an already developed solution.

I admit that I can be very far in terms of possible ideas about this. Please excuse my ignorance.

+3
source share
3 answers

.so ( .pyd) ( ), . .py /; Python, "". Python .

.py , , CPython.

, , , Python .so, Cython. .

+1

, . Python , , , - , , , . , , -, , , .

0

, , - ", , ".

, . .py , Python , . .

.so , , . , .

Python already has a third way to load modules. If possible, when you download the .py file, it creates a precompiled .pyc file that loads faster (you avoid compilation). Next time it will download the .pyc file. Perhaps they could have a .pyc file just paste it into memory. (Using MAP_PRIVATE in case other things get corrupted with this byte code later.) If they do, then common modules will be included in shared memory by default.

I do not know if this is really implemented in this way.

0
source

Source: https://habr.com/ru/post/1793640/


All Articles