小编mpa*_*paf的帖子

如何将一系列任务路由到芹菜中的特定队列?

当我将任务路由到特定队列时,它可以工作:

task.apply_async(queue='beetroot')
Run Code Online (Sandbox Code Playgroud)

但如果我创建一个链:

chain = task | task
Run Code Online (Sandbox Code Playgroud)

然后我写

chain.apply_async(queue='beetroot')
Run Code Online (Sandbox Code Playgroud)

它似乎忽略了queue关键字并分配给默认的'celery'队列.

如果芹菜支持链中的路由会很好 - 所有任务在同一队列中按顺序执行.

python rabbitmq celery chain

12
推荐指数
3
解决办法
6910
查看次数

如果浏览器不支持HTML5的<video>标记,如何显示图像

有谁知道如何为不支持标签的浏览器显示图像?显示如下的文本:

<video src="video.mp4" type="video/mp4">
    Your browser does not support the <video> tag
</video>
Run Code Online (Sandbox Code Playgroud)

很容易,但如果我用img标签替换文本,它将始终显示图像,即使浏览器支持视频标签.

感谢您分享您的知识

(编辑)事实并非如此,我的测试错了,只有在不支持视频时才会呈现img标签(例如Safari 5)

tags video html5 image alt

10
推荐指数
1
解决办法
2万
查看次数

Postgresql:在不同的客户端中查询速度慢10倍

查看postgres服务器日志,我发现从Linux客户端或Windows客户端调用时,同一postgres服务器上的完全相同的查询需要更长的时间(大约长10倍).

查询来自运行在具有4GB RAM的Linux机器上的Django应用程序以及具有8GB RAM的Windows机器上.两个pyhon环境都有psycopg2库版本2.4.4将请求发送到同一postgres服务器.

以下是postgres服务器日志

windows查询(带时间):

2013-06-11 12:12:19 EEST [unknown] 10.1.3.152(56895) mferreiraLOG:  duration: 3207.195 ms  statement: SELECT "autotests_tracerperformance"."id", "autotests_tracerperformance"."date", "autotests_tracerperformance"."video_id", "autotests_tracerperformance"."revision_id", "autotests_tracerperformance"."computer_id", "autotests_tracerperformance"."probe", "autotests_tracerperformance"."time_tostart", "autotests_tracerperformance"."hang_atstart", "autotests_tracerperformance"."time_tohang", "autotests_tracerperformance"."hang", "autotests_tracerperformance"."crash", "autotests_tracerperformance"."stacktrace", "autotests_tracerperformance"."framemax", "autotests_tracerperformance"."maxtime", "autotests_tracerperformance"."avgtime" FROM "autotests_tracerperformance" INNER JOIN "revisions" ON ("autotests_tracerperformance"."revision_id" = "revisions"."id") WHERE ("autotests_tracerperformance"."computer_id" = 61  AND "revisions"."repo" = 'Trunk' )
Run Code Online (Sandbox Code Playgroud)

linux查询(更长):

2013-06-11 12:12:56 EEST [unknown] 10.1.3.154(35325) mferreiraLOG:  duration: 22191.773 ms  statement: SELECT "autotests_tracerperformance"."id", "autotests_tracerperformance"."date", "autotests_tracerperformance"."video_id", "autotests_tracerperformance"."revision_id", "autotests_tracerperformance"."computer_id", "autotests_tracerperformance"."probe", "autotests_tracerperformance"."time_tostart", "autotests_tracerperformance"."hang_atstart", "autotests_tracerperformance"."time_tohang", "autotests_tracerperformance"."hang", "autotests_tracerperformance"."crash", "autotests_tracerperformance"."stacktrace", "autotests_tracerperformance"."framemax", "autotests_tracerperformance"."maxtime", "autotests_tracerperformance"."avgtime" FROM "autotests_tracerperformance" INNER …
Run Code Online (Sandbox Code Playgroud)

python django postgresql psycopg2

8
推荐指数
1
解决办法
1855
查看次数

使用内联表单呈现django-crispy-forms中的字段错误

我正在使用bootstrap3作为django_crispy_forms中的默认模板包,并尝试使用crispy标签呈现表单:

{% crispy form %}
Run Code Online (Sandbox Code Playgroud)

我的表单类具有以下帮助器属性:

class TheForm(forms.Form):
    adv_var = forms.CharField(label="variable", max_length=70)
    value = forms.FloatField()

    def __init__(self, *args, **kwargs):
        super(TheForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()

        self.helper.form_method = 'post'
        self.helper.form_class = 'form-inline'
        self.helper.field_template = 'bootstrap3/layout/inline_field.html'

        self.helper.layout = Layout(
            'adv_var', 'value',
            ButtonHolder(
                Submit('submit', 'Start', css_class='button white')
            )
        )
Run Code Online (Sandbox Code Playgroud)

发布带有错误的表单时,即使我可以在视图中打印form._errors并查看错误列表,重新呈现模板也不会显示错误.

如果我将helper.field_template更改为另一个值(或删除它以设置默认值),错误将显示在每个字段上方 - 但我不再获得内联显示.

我如何使用django-crispy-forms在单独的div中显示此表单的所有错误?

django django-crispy-forms

8
推荐指数
1
解决办法
8644
查看次数

在芹菜的@task装饰员之后的装饰员

我正试图在芹菜@task装饰器之后应用装饰器,类似于.

@send_email
@task
def any_function():

   print "inside the function"
Run Code Online (Sandbox Code Playgroud)

我可以按照文档中推荐的方式工作,即将装饰器放在任务装饰器之前,但在这种情况下我想访问装饰器中的任务实例.

@send_email必须是一个类装饰器,这是我试过没有成功的:

class send_email(object):
    ''' wraps a Task celery class '''
    def __init__(self, obj):

        self.wrapped_obj = obj

        functools.update_wrapper(self, obj)

    def __call__(self, *args, **kwargs):

        print "call"

        return self.wrapped_obj.__call__(*args, **kwargs)

    def run(self, *args, **kwargs):

        print "run"

        return self.wrapped_obj.__call__(*args, **kwargs)

    def __getattr__(self, attr):

        if attr in self.__dict__:

            return getattr(self, attr)

        return getattr(self.wrapped_obj, attr)
Run Code Online (Sandbox Code Playgroud)

我永远无法在调用或运行函数函数中获取print语句以显示在worker或调用者中.

我们如何装饰芹菜任务,而不依赖于基于类的任务定义(因此装饰器将位于函数定义之上的@task之上).

谢谢你的帮助!

米格尔

python decorator celery django-celery

7
推荐指数
2
解决办法
6054
查看次数

Django:在一个单独的线程中使用相同的测试数据库

我正在使用具有以下数据库设置的测试数据库运行pytests.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'postgres',
        'USER': 'something',
        'PASSWORD': 'password',

    },
}
Run Code Online (Sandbox Code Playgroud)

使用@ pytest.mark.django_db,我的测试函数访问为测试创建的名为'test_postgres'的数据库.

@pytest.mark.django_db
def test_example():
    from django.db import connection
    cur_ = connection.cursor()
    print cur_.db.settings_dict
Run Code Online (Sandbox Code Playgroud)

输出:

{'ENGINE': 'django.db.backends.postgresql_psycopg2', 'AUTOCOMMIT': True, 'ATOMIC_REQUESTS': False, 'NAME': 'test_postgres', 'TEST_MIRROR': None,...
Run Code Online (Sandbox Code Playgroud)

但如果我在test_example中运行一个线程:

def function_to_run():
    from django.db import connection
    cur_ = connection.cursor
    logger.error(cur_.db.settings_dict)

@pytest.mark.django_db
def test_example():
    p = multiprocessing.Process(target=function_to_run)
    p.start()
Run Code Online (Sandbox Code Playgroud)

我可以看到,在该线程中,游标使用名为'postgres'的数据库,这是非测试数据库.输出:

{'ENGINE': 'django.db.backends.postgresql_psycopg2', 'AUTOCOMMIT': True, 'ATOMIC_REQUESTS': False, 'NAME': 'postgres', 'TEST_MIRROR': None,...
Run Code Online (Sandbox Code Playgroud)

有没有办法将数据库连接参数从原始测试函数传递给我的线程,并告诉我的线程例程使用相同的数据库名称('test_postgres')作为我的测试函数?

python django psycopg2 pytest

7
推荐指数
1
解决办法
2965
查看次数

通过 ssh 运行远程 Windows GUI 应用程序

我正在使用 py.test 运行一系列测试外部 Windows GUI 应用程序的 python 脚本。

我正在尝试使用 Fabric(在远程端使用 Bitvise SSH 服务器)在启用 ssh 的远程 Windows 计算机上运行这些测试,但是需要 GUI 访问的测试当然会失败。

我知道 py.test 有一个名为 xdist 的包,但我想如果我们使用的通道是 SSH,它也会遇到同样的问题。

有人解决了通过 SSH 在 Windows 中运行远程 GUI 应用程序的问题吗?SSH 对我来说运行远程部署命令非常方便,从逻辑上讲 py.test 将是此类命令之一。

python ssh pytest

5
推荐指数
0
解决办法
1042
查看次数