Python - Web服务器可以避免针对每个请求引起注意? [英] Python - Can a web server avoid imporing for every request?

查看:212
本文介绍了Python - Web服务器可以避免针对每个请求引起注意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Python项目,目前正在使用Django,它在表单后期处理中做了很多NLP工作。我使用NLTK包,并分析我的代码和实验,我已经意识到代码所需的大部分时间是执行NLTK和其他各种包的导入过程。我的问题是,有没有办法我可以让这个服务器启动,做这些导入,然后只是等待请求,传递给使用已经导入的包的功能?这将比每次请求执行这样的进口要快得多,浪费更少。如果有任何人有任何想法,以避免在每个请求上导入大包,如果您能帮助我,这将是非常好的!

I'm working on a Python project, currently using Django, which does quite a bit of NLP work in a form post process. I'm using the NLTK package, and profiling my code and experimenting I've realised that the majority of the time the code takes is performing the import process of NLTK and various other packages. My question is, is there a way I can have this server start up, do these imports and then just wait for requests, passing them to a function that uses the already imported packages? This would be much faster and less wasteful than performing such imports on every request. If anybody has any ideas to avoid importing large packages on every request, it'd be great if you could help me out!

谢谢
Callum


Thanks, Callum

推荐答案

Django在大多数部署机制下,为每个请求都不导入模块。即使开发服务器只是在更改时重新加载代码。我不知道你如何验证所有的进口是否每次重新运行,但这绝对不会发生。

Django, under most deployment mechanism, does not import modules for every request. Even the development server only reloads code when it changes. I don't know how you're verifying that all the imports are re-run each time, but that certainly shouldn't be happening.

这篇关于Python - Web服务器可以避免针对每个请求引起注意?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆