我正试图将浮士德与德扬戈结合起来,将这些信息发布给卡夫卡。 以下是《浮士德报告》中的例子:https://github.com/robinhood/faust/tree/master/examples/django
我对它做了一些修改,创建了视图,通过浮士德将数据推送到卡夫卡
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")
但是,我现在得到了这个错误:
RuntimeError at / Task <Task pending name='Task-1' coro=<AsyncToSync.main_wrap() running at /Users/mysuer/.pyenv/versions/3.8.3/envs/faustdjango/lib/python3.8/site-packages/asgiref/sync.py:204> cb=[_run_until_complete_cb() at /Users/mysuer/.pyenv/versions/3.8.3/lib/python3.8/asyncio/base_events.py:184]> got Future attached to a different loop
我正在使用开发服务器运行这个Django应用程序。 我做错了什么? 有人吗?:)
请参阅faust documentation中的常见问题部分
我可以将浮士德与Django/Flask/等一起使用吗?
对!!使用
eventlet
作为与asyncio
集成的桥梁使用
eventlet
这种方法适用于任何可以使用
eventlet
的阻塞Python库使用
eventlet
需要安装aioeventlet
模块,您可以将其作为捆绑包与Faust一起安装:然后,要实际使用eventlet作为事件循环,您必须使用
-L <faust loop>
程序的faust
参数:或者在入口点脚本的顶部添加
import mode.loop.eventlet
:相关问题 更多 >
编程相关推荐