日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python多个进度条_多个芹菜进度条

發布時間:2023/12/1 python 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python多个进度条_多个芹菜进度条 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

問題

我有一個Django站點,使用celeri+RabbitMQ作為長時間運行任務的任務隊列。我把結果存儲在Redis中。我已經能夠使用Celery的update_state在引導進度條中顯示一個任務的進度,并通過一個按鈕向Redis DB發送ajax post來檢索當前狀態。在

理想情況下,我想顯示每個任務當前正在運行或最近完成,是在Redis與它自己的進度條。目前,我只能顯示由我的小Click Here按鈕啟動的當前任務的進度。在

我試著為進度條制作多個類,但老實說,我不知道該怎么做,似乎找不到任何關于如何做這樣的事情的東西。我試著上傳盡可能多的代碼。任何幫助將不勝感激!在

代碼

在網址.pyurlpatterns = [

url(r'^poll_state$', poll_state, name="poll_state"),

url(r'^do_task$', do_task, name="do_task"),

]

在視圖.py

^{pr2}$

在任務.pyfrom __future__ import absolute_import, unicode_literals

from celery import shared_task

from celery.decorators import task

from celery import current_task

from celery.result import AsyncResult

import celery

from .celery import app

import time

#Task loops every half second to update the current state

@task(bind=True, ignore_result=True)

def add(self):

for i in range(101):

time.sleep(0.5)

self.update_state(state="PROGRESS", meta={'current': i, 'total': 100})

在芹菜from __future__ import absolute_import, unicode_literals

import os

from celery import Celery

from django.conf import settings

# set the default Django settings module for the 'celery' program.

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'yodaclaw.settings')

app = Celery('myAppName')

# Using a string here means the worker doesn't have to serialize

# the configuration object to child processes.

# - namespace='CELERY' means all celery-related configuration keys

# should have a `CELERY_` prefix.

app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.

# This allows you in shell to not have to import yodaclaw.tasks

app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

@app.task

def debug_task(self):

print('Request: {0!r}'.format(self.request))

在設置.py# Celery Settings

CELERY_BROKER_URL = 'amqp://localhost'

CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'

CELERY_ACCEPT_CONTENT = ['application/json']

CELERY_ACCEPT_CONTENT = ['json']

CELERY_TASK_SERIALIZER = 'json'

CELERY_TRACK_STARTED = True

在基準.py{% load static %}

{% block title_outer %}

{% endblock %}

{% block meta %}

{% endblock %}

{% block stylesheets %}

{% endblock %}

{% block javascript %}

{% endblock %}

{% block extra_head %}

{% endblock %}

{% block body %}

{% block nav_header %}

{% endblock %}

{% block nav_sidebar %}

{% endblock %}

{% block content_wrapper %}

{% block content_header %}

{% endblock %}

{% block content_outer %}

{% block messages %}

{% endblock %}

{% block content_block_wrap %}

{% block content %}{% endblock %}

{% endblock %}

{% endblock %}

{% endblock content_wrapper %}

{% block nav_footer %}

{% endblock %}

{% if task_id %}

Task ID: {{ task_id }}

aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">

{% if task_id %} {{ task_id }} {% endif %}

{% endif %}

Click here!

{% if task_id %}

jQuery(document).ready(function() {

var PollState = function(task_id) {

jQuery.ajax({

url: "poll_state",

type: "POST",

data: "task_id=" + task_id,

}).done(function(task) {

if (task.current) {

jQuery('.progress-bar').css({'width': task.current + '%'});

jQuery('.progress-bar').html(task.current + '%');

}

else {

jQuery('.status').html(task);

};

PollState(task_id);

});

}

PollState('{{ task_id }}');

})

{% endif %}

jQuery('#do-task').click( function() {

jQuery.ajax({

url: "do_task",

data: {},

success: function(){

jQuery.ajax({

url: "",

context: document.body,

success: function(s, x) {

jQuery(this).html(s);

}

});

}

})

});

{% endblock body %}

{% block extra_foot %}{% endblock %}

總結

以上是生活随笔為你收集整理的python多个进度条_多个芹菜进度条的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。