Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何整合浮士德与德扬戈?_Python_Django_Django 3.0_Faust_Django 3.1 - Fatal编程技术网

Python 如何整合浮士德与德扬戈?

Python 如何整合浮士德与德扬戈?,python,django,django-3.0,faust,django-3.1,Python,Django,Django 3.0,Faust,Django 3.1,我正试图将浮士德与德扬戈结合起来,将这些信息发布给卡夫卡。 以下是浮士德回购的例子: 我对它做了一些修改,创建了视图,通过浮士德将数据推送到卡夫卡 from django.shortcuts import render from asgiref.sync import async_to_sync from accounts.agents import AccountRecord, add_account async def send_data() -> None: prin

我正试图将浮士德与德扬戈结合起来,将这些信息发布给卡夫卡。 以下是浮士德回购的例子:

我对它做了一些修改,创建了视图,通过浮士德将数据推送到卡夫卡

from django.shortcuts import render

from asgiref.sync import async_to_sync

from accounts.agents import AccountRecord, add_account


async def send_data() -> None:
    print("sending..data")
    print(await add_account.ask(AccountRecord(name="tesst", score=10.9, active=False)))

def index(request):
    async_to_sync(send_data)()
    return render(request, "accounts/index.html")
但是,我现在得到了这个错误:

运行时错误/任务 将Future附加到另一个循环

我正在使用开发服务器运行这个Django应用程序。 我做错了什么?
有人吗?:)

参见《浮士德》中的常见问题部分

我可以将浮士德与Django/Flask/等一起使用吗?

对!!使用
eventlet
作为与
asyncio
集成的桥梁

使用
eventlet

这种方法适用于任何可以使用
eventlet
的阻塞Python库

使用
eventlet
需要安装
aioeventlet
模块,您可以将其作为捆绑包与Faust一起安装:

$ pip install -U faust[eventlet]
然后,要实际使用eventlet作为事件循环,您必须使用
faust
程序的
-L
参数:

$ faust -L eventlet -A myproj worker -l info
或者在入口点脚本的顶部添加
import mode.loop.eventlet

#/usr/bin/env蟒蛇3
导入模式.loop.eventlet#noqa
警告 非常重要的是,它位于模块的最顶端,并且在导入库之前执行


你能提供完整的代码吗。而且,上面的链接也有相同的错误和答案。你检查过了吗?@Maverick,你是如何在Django中作为主应用程序执行此操作的?根据的示例,他们确保使用事件循环,方法是确保启动的应用程序使用
faust.app()
我相信,当您尝试运行在不同线程(或进程)中自行执行的函数时,会发生这种情况。正如我在faustapp源代码中看到的,它被定义为异步函数,因此不能将其称为同步函数。这一点都没有帮助,因为它仍然没有解释如何从视图向代理发送调用。所有文档都没有——甚至他们的Django示例也没有。