推荐学习书目
› 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 · Oct 4, 2024 · 4784 views
    This topic created in 732 days ago, the information mentioned may be changed or developed.

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

    3 replies  •  2024-10-04 13:45:03 +08:00
    way2explore2
        1
    way2explore2  
       Oct 4, 2024
    不支持啊
    有讨论过啊,

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


    不过,将来也许会支持,Django Ninja 已经部分支持
    JasperYanky
        2
    JasperYanky  
       Oct 4, 2024
    用不 celery 用 huey 试试?
    dearmymy
        3
    dearmymy  
    OP
       Oct 4, 2024   ❤️ 1
    @way2explore2 我又搜了下,貌似可以用 adrf ,既可以用异步视图,又是扩展原来的 drf
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2589 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 34ms · UTC 14:37 · PVG 22:37 · LAX 07:37 · JFK 10:37
    ♥ Do have faith in what you're doing.