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
334862132
V2EX  ›  Python

一个接口调用另一个接口,不需要返回数据,除了异步还有没有其他方法

  •  
  •   334862132 · 2018-11-09 10:06:20 +08:00 · 1919 次点击
    这是一个创建于 1987 天前的主题,其中的信息可能已经有所发展或是发生改变。
    代码 用 django 做的测试代码
    我不需要 test 接口的返回结果,直接返回前端数据 除了异步处理还有没有其他的方法?

    def startPage(request):
    try:
    data = {'start':func.now_time()}
    test()
    data['end'] = func.now_time()
    return HttpResponse(func.visitSuccess(data=data))
    except:
    return HttpResponse(func.visitFail())

    def test():
    print(func.now_time())
    time.sleep(10)
    print(func.now_time())


    postman 返回结果
    {
    "code": 200,
    "msg": "成功",
    "data": {
    "start": "2018-11-09 09:42:58",
    "end": "2018-11-09 09:43:08"
    }}
    2 条回复    2018-11-09 10:24:31 +08:00
    ifoolish
        1
    ifoolish  
       2018-11-09 10:15:09 +08:00   ❤️ 1
    这么简单的场景,有没有并发需求,一个请求开一个线程不就完了
    wysnylc
        2
    wysnylc  
       2018-11-09 10:24:31 +08:00   ❤️ 1
    并行
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3468 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 80ms · UTC 11:13 · PVG 19:13 · LAX 04:13 · JFK 07:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.