简体   繁体   English

Django 应用程序 - 服务器上的数据处理

[英]Django app - data processing on the server

I have some question about some django app.我对一些 django 应用程序有一些疑问。

Simple example:简单的例子:

On the server I'd like to run some program, which should display some value.在服务器上我想运行一些程序,它应该显示一些值。 Example:例子:

for(i in range(10)):
    print(10**i)
    sleep(1)

So value changes every 1 second without refreshing.因此值每 1 秒更改一次,无需刷新。 It could be some progress bar etc.它可能是一些进度条等。

How to start with it?如何开始呢? Celery is the good start? Celery 是好的开始吗? What should I look for?我应该寻找什么?

Best regards!此致!

Edit: It could be somethink like progress bar etc.编辑:可能是进度条等。

For example only x% value on my page.例如,我的页面上只有 x% 的值。 And some data should be processed in the background.并且一些数据应该在后台处理。

You know what I mean?你知道我的意思?

You can use Twisted which is a Python networking library.您可以使用 Twisted,它是一个 Python 网络库。

From the documentation:从文档中:

from twisted.internet import task, reactor
timeout = 60.0 #specify interval over here in seconds

def doWork():
    #do whatever work you want to do here
    pass

rep_work = task.LoopingCall(doWork)
rep_work.start(timeout) # call every sixty seconds
reactor.run()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM