Python — Limits On Number of Imports?

前端 未结 3 559
慢半拍i
慢半拍i 2021-02-14 14:00

I have 1000s of custom (compiled to \'.so\') modules that I\'d like to use in python at the same time. Each such module is of size (100 [KB]) on averag

3条回答
  •  遥遥无期
    2021-02-14 14:26

    The amount of memory consumed by a single imported module is going to be at least as big as the size of the module on disk. The overhead is determined by both the OS itself (for loading a dynamic module) and Python's overhead in importing a module.

    So if your module are on average 100kB in size, then importing 10000 of them will take up at least 1 GB of address space. Importing 50000 of them will run over 5 GB. You'd better be using an operating system with a 64-bit address space.

提交回复
热议问题