开发者

Interacting with a program in the background of Django

I have a program that classifies text and would like to make it interactive with a user on the front-end of my django site. The problem is it takes 20 seconds for the program to load the training set and get going, and that's not feasible every time someone enters input.

Instead, I'd like Django to load the program once when the server starts, and have all user input interact with it via a view.

I looked at launching subprocesses, but if I'm not mistaken, a subprocess would only be launched when a view is called and that is undesirable for this.

Any id开发者_运维问答eas?

Thanks.


It's possible that Celery would be appropriate here. There is Django integration available with django-celery.


As Jim noticed celery is one of the best options you have for asynchronus task management, but if you want to avoid celery & its dependecies overhead you could just add a status field on the model the process takes place (e.g. text_processed boolean field with default=False) and create an application management command which would handle the process of the created db entries.

Add the command on a cron and you are done.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜