Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
tornadoweb
Tornado
提交
48073bf4
Tornado
项目概览
镜像
/
tornadoweb
/
Tornado
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
48073bf4
编写于
3月 18, 2018
作者:
B
Ben Darnell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gen: Deprecate callback argument to coroutines
上级
0e43388c
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
21 addition
and
13 deletion
+21
-13
tornado/gen.py
tornado/gen.py
+7
-1
tornado/simple_httpclient.py
tornado/simple_httpclient.py
+6
-5
tornado/test/gen_test.py
tornado/test/gen_test.py
+7
-5
tornado/test/tcpclient_test.py
tornado/test/tcpclient_test.py
+1
-2
未找到文件。
tornado/gen.py
浏览文件 @
48073bf4
...
...
@@ -240,7 +240,7 @@ def engine(func):
return
wrapper
def
coroutine
(
func
,
replace_callback
=
True
):
def
coroutine
(
func
):
"""Decorator for asynchronous generators.
Any generator that yields objects from this module must be wrapped
...
...
@@ -274,6 +274,10 @@ def coroutine(func, replace_callback=True):
`.IOLoop.run_sync` for top-level calls, or passing the `.Future`
to `.IOLoop.add_future`.
.. deprecated:: 5.1
The ``callback`` argument is deprecated and will be removed in 6.0.
Use the returned awaitable object instead.
"""
return
_make_coroutine_wrapper
(
func
,
replace_callback
=
True
)
...
...
@@ -296,6 +300,8 @@ def _make_coroutine_wrapper(func, replace_callback):
future
=
_create_future
()
if
replace_callback
and
'callback'
in
kwargs
:
warnings
.
warn
(
"callback arguments are deprecated, use the returned Future instead"
,
DeprecationWarning
,
stacklevel
=
2
)
callback
=
kwargs
.
pop
(
'callback'
)
IOLoop
.
current
().
add_future
(
future
,
lambda
future
:
callback
(
future
.
result
()))
...
...
tornado/simple_httpclient.py
浏览文件 @
48073bf4
...
...
@@ -227,10 +227,10 @@ class _HTTPConnection(httputil.HTTPMessageDelegate):
self
.
_timeout
=
self
.
io_loop
.
add_timeout
(
self
.
start_time
+
timeout
,
stack_context
.
wrap
(
functools
.
partial
(
self
.
_on_timeout
,
"while connecting"
)))
self
.
tcp_client
.
connect
(
host
,
port
,
af
=
af
,
ssl_options
=
ssl_options
,
max_buffer_size
=
self
.
max_buffer_size
,
callback
=
self
.
_on_connect
)
fut
=
self
.
tcp_client
.
connect
(
host
,
port
,
af
=
af
,
ssl_options
=
ssl_options
,
max_buffer_size
=
self
.
max_buffer_size
)
fut
.
add_done_callback
(
stack_context
.
wrap
(
self
.
_on_connect
)
)
def
_get_ssl_options
(
self
,
scheme
):
if
scheme
==
"https"
:
...
...
@@ -275,7 +275,8 @@ class _HTTPConnection(httputil.HTTPMessageDelegate):
self
.
io_loop
.
remove_timeout
(
self
.
_timeout
)
self
.
_timeout
=
None
def
_on_connect
(
self
,
stream
):
def
_on_connect
(
self
,
stream_fut
):
stream
=
stream_fut
.
result
()
if
self
.
final_callback
is
None
:
# final_callback is cleared if we've hit our timeout.
stream
.
close
()
...
...
tornado/test/gen_test.py
浏览文件 @
48073bf4
...
...
@@ -821,7 +821,8 @@ class GenCoroutineTest(AsyncTestCase):
yield
gen
.
Task
(
self
.
io_loop
.
add_callback
)
raise
gen
.
Return
(
43
)
f2
(
callback
=
(
yield
gen
.
Callback
(
'cb'
)))
with
ignore_deprecation
():
f2
(
callback
=
(
yield
gen
.
Callback
(
'cb'
)))
results
=
yield
[
namespace
[
'f1'
](),
gen
.
Wait
(
'cb'
)]
self
.
assertEqual
(
results
,
[
42
,
43
])
self
.
finished
=
True
...
...
@@ -885,10 +886,11 @@ class GenCoroutineTest(AsyncTestCase):
@
gen_test
def
test_pass_callback
(
self
):
@
gen
.
coroutine
def
f
():
raise
gen
.
Return
(
42
)
result
=
yield
gen
.
Task
(
f
)
with
ignore_deprecation
():
@
gen
.
coroutine
def
f
():
raise
gen
.
Return
(
42
)
result
=
yield
gen
.
Task
(
f
)
self
.
assertEqual
(
result
,
42
)
self
.
finished
=
True
...
...
tornado/test/tcpclient_test.py
浏览文件 @
48073bf4
...
...
@@ -77,8 +77,7 @@ class TCPClientTest(AsyncTestCase):
def
skipIfLocalhostV4
(
self
):
# The port used here doesn't matter, but some systems require it
# to be non-zero if we do not also pass AI_PASSIVE.
Resolver
().
resolve
(
'localhost'
,
80
,
callback
=
self
.
stop
)
addrinfo
=
self
.
wait
()
addrinfo
=
yield
Resolver
().
resolve
(
'localhost'
,
80
)
families
=
set
(
addr
[
0
]
for
addr
in
addrinfo
)
if
socket
.
AF_INET6
not
in
families
:
self
.
skipTest
(
"localhost does not resolve to ipv6"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录