print int(time.time())
name = "scrapy.extensions.memusage"
__import__(name)
print int(time.time())
执行本段代码耗时30秒,请教可能是什么原因呢?
感谢大神的回答,原因确实是依赖导致的。
我的具体原因是:
hostname, aliases, ipaddrs = gethostbyaddr(name)
这个方法导致的, 跟获取服务器名有关,
解决办法是zai /etc/hosts中加入本机名 解决!
I tested the above code and
import scrapy.extensions.memusage
both take around 4sIt should be that scrapy.extensions.memusage has too many dependencies, causing the slow speed
should have nothing to do with __import__
And the official does not recommend using this import module...
The first two people should have answered LZ’s question, but I want to add something
These two lines are completely equivalent! If you really want to introduce
scrapy.extensions.memusage
, then you should write like thisHowever, it is of no use. Both of my SSD tests took about 2s.
scrapy.extensions.memusage imports a lot of dependencies by default, which is of course slow. See the number of sys.modules before and after importing this module