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

2018-11-09 10:06:20 +08:00
 334862132
代码 用 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"
}}
1927 次点击
所在节点    Python
2 条回复
ifoolish
2018-11-09 10:15:09 +08:00
这么简单的场景,有没有并发需求,一个请求开一个线程不就完了
wysnylc
2018-11-09 10:24:31 +08:00
并行

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/506003

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX