这是一个创建于 2298 天前的主题,其中的信息可能已经有所发展或是发生改变。
代码 用 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
 |
|
1
ifoolish 2018-11-09 10:15:09 +08:00 1
这么简单的场景,有没有并发需求,一个请求开一个线程不就完了
|
 |
|
2
wysnylc 2018-11-09 10:24:31 +08:00 1
并行
|