Importing a function from a module takes a lot of time

When I import my self-written module function into a python script, loading takes about 6 seconds. The function contains only about 50 lines of code, but it should not matter, since it has not yet been executed correctly?

This is the script that loads the function:

#/usr/bin/env python

import time
print(time.clock())
from os import chdir
print(time.clock())
from os.path import abspath, dirname
print(time.clock())
from Project.controllers.SpiderController import RunSpider
print(time.clock())

And the output is as follows:

0.193569
0.194114
0.194458
6.315348

I also tried to import the whole module, but the result was the same.

What could be the reason for this?

Some notes:

  • I am using python 2.7.9
  • The module uses the scrapy structure
  • python script runs on raspberry Pi 1 Model B
+4
source share
1 answer

, ?

, . , , , .. , ( ).

from <module> import <item> , .

, , if __name__ == '__main__': .

, , ​​, :

def foo(x):
    return x + 5

def bar(y):
    return y * 2

def qux(x):
    return foo(bar(x))

from module import qux, foo bar, qux.

, , : ( ..).

, , __init__.py, . . , , , , , .

+3

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


All Articles