Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
tornadoweb
Tornado
提交
e4e9dbb6
Tornado
项目概览
镜像
/
tornadoweb
/
Tornado
大约 1 年 前同步成功
通知
26
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Tornado
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e4e9dbb6
编写于
3月 11, 2018
作者:
B
Ben Darnell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
concurrent: run_on_executor returns async futures, not concurrent ones
Fixes #2276
上级
cfd621a3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
4 deletion
+30
-4
tornado/concurrent.py
tornado/concurrent.py
+9
-3
tornado/test/concurrent_test.py
tornado/test/concurrent_test.py
+21
-1
未找到文件。
tornado/concurrent.py
浏览文件 @
e4e9dbb6
...
...
@@ -421,6 +421,10 @@ def run_on_executor(*args, **kwargs):
.. versionchanged:: 5.0
Always uses the current IOLoop instead of ``self.io_loop``.
.. versionchanged:: 5.1
Returns a `.Future` compatible with ``await`` instead of a
`concurrent.futures.Future`.
"""
def
run_on_executor_decorator
(
fn
):
executor
=
kwargs
.
get
(
"executor"
,
"executor"
)
...
...
@@ -428,12 +432,14 @@ def run_on_executor(*args, **kwargs):
@
functools
.
wraps
(
fn
)
def
wrapper
(
self
,
*
args
,
**
kwargs
):
callback
=
kwargs
.
pop
(
"callback"
,
None
)
future
=
getattr
(
self
,
executor
).
submit
(
fn
,
self
,
*
args
,
**
kwargs
)
async_future
=
Future
()
conc_future
=
getattr
(
self
,
executor
).
submit
(
fn
,
self
,
*
args
,
**
kwargs
)
chain_future
(
conc_future
,
async_future
)
if
callback
:
from
tornado.ioloop
import
IOLoop
IOLoop
.
current
().
add_future
(
future
,
lambda
future
:
callback
(
future
.
result
()))
return
future
async_
future
,
lambda
future
:
callback
(
future
.
result
()))
return
async_
future
return
wrapper
if
args
and
kwargs
:
raise
ValueError
(
"cannot combine positional and keyword args"
)
...
...
tornado/test/concurrent_test.py
浏览文件 @
e4e9dbb6
...
...
@@ -31,7 +31,7 @@ from tornado.log import app_log
from
tornado
import
stack_context
from
tornado.tcpserver
import
TCPServer
from
tornado.testing
import
AsyncTestCase
,
ExpectLog
,
bind_unused_port
,
gen_test
from
tornado.test.util
import
unittest
from
tornado.test.util
import
unittest
,
skipBefore35
,
exec_test
try
:
...
...
@@ -429,6 +429,26 @@ class RunOnExecutorTest(AsyncTestCase):
answer
=
yield
o
.
f
()
self
.
assertEqual
(
answer
,
42
)
@
skipBefore35
@
gen_test
def
test_async_await
(
self
):
class
Object
(
object
):
def
__init__
(
self
):
self
.
executor
=
futures
.
thread
.
ThreadPoolExecutor
(
1
)
@
run_on_executor
()
def
f
(
self
):
return
42
o
=
Object
()
namespace
=
exec_test
(
globals
(),
locals
(),
"""
async def f():
answer = await o.f()
return answer
"""
)
result
=
yield
namespace
[
'f'
]()
self
.
assertEqual
(
result
,
42
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录