V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
dearmymy
V2EX  ›  Python

django 在 drf 同步视图模拟异步么

  •  
  •   dearmymy · 18 天前 · 1021 次点击

    项目本身一直使用 drf ,包括鉴权什么得。 现在有一个小需求,用户请求我服务器,我代码调用一个第三方 http 服务。我看 drf 使用异步处理很有问题,貌似没法用类似 permission_classes 这些特性。而且这个接口使用量也不大,不想搞得那么麻烦在上 celery 里。 有没有什么办法 可以让同步 drf 接口,去异步执行(线程模拟也行)一个同步函数,然后在返回给用户。中间不阻塞其他 http 请求。问了 claude 跟 gpt ,给得方案都会堵塞其他 http 请求。请问这种需求有什么好得解决方案么。实在不想用 celery

    3 条回复    2024-10-04 13:45:03 +08:00
    way2explore2
        1
    way2explore2  
       18 天前
    不支持啊
    有讨论过啊,

    https://github.com/encode/django-rest-framework/discussions/7774


    不过,将来也许会支持,Django Ninja 已经部分支持
    JasperYanky
        2
    JasperYanky  
       18 天前
    用不 celery 用 huey 试试?
    dearmymy
        3
    dearmymy  
    OP
       18 天前   ❤️ 1
    @way2explore2 我又搜了下,貌似可以用 adrf ,既可以用异步视图,又是扩展原来的 drf
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5160 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 09:38 · PVG 17:38 · LAX 02:38 · JFK 05:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.