Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
bc565e3b
Commit
bc565e3b
authored
Oct 05, 2016
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28372: Fix asyncio to support formatting of non-python coroutines
parent
2356964d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
0 deletions
+55
-0
Lib/asyncio/coroutines.py
Lib/asyncio/coroutines.py
+19
-0
Lib/test/test_asyncio/test_events.py
Lib/test/test_asyncio/test_events.py
+34
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/asyncio/coroutines.py
View file @
bc565e3b
...
...
@@ -261,6 +261,25 @@ def iscoroutine(obj):
def
_format_coroutine
(
coro
):
assert
iscoroutine
(
coro
)
if
not
hasattr
(
coro
,
'cr_code'
)
and
not
hasattr
(
coro
,
'gi_code'
):
# Most likely a Cython coroutine.
coro_name
=
getattr
(
coro
,
'__qualname__'
,
coro
.
__name__
)
coro_name
=
'{}()'
.
format
(
coro_name
)
running
=
False
try
:
running
=
coro
.
cr_running
except
AttributeError
:
try
:
running
=
coro
.
gi_running
except
AttributeError
:
pass
if
running
:
return
'{} running'
.
format
(
coro_name
)
else
:
return
coro_name
coro_name
=
None
if
isinstance
(
coro
,
CoroWrapper
):
func
=
coro
.
func
...
...
Lib/test/test_asyncio/test_events.py
View file @
bc565e3b
"""Tests for events.py."""
import
collections.abc
import
functools
import
gc
import
io
...
...
@@ -25,6 +26,7 @@ if sys.platform != 'win32':
import
tty
import
asyncio
from
asyncio
import
coroutines
from
asyncio
import
proactor_events
from
asyncio
import
selector_events
from
asyncio
import
sslproto
...
...
@@ -2380,6 +2382,38 @@ class HandleTests(test_utils.TestCase):
h
=
loop
.
call_later
(
0
,
noop
)
check_source_traceback
(
h
)
@
unittest
.
skipUnless
(
hasattr
(
collections
.
abc
,
'Coroutine'
),
'No collections.abc.Coroutine'
)
def
test_coroutine_like_object_debug_formatting
(
self
):
# Test that asyncio can format coroutines that are instances of
# collections.abc.Coroutine, but lack cr_core or gi_code attributes
# (such as ones compiled with Cython).
class
Coro
:
__name__
=
'AAA'
def
send
(
self
,
v
):
pass
def
throw
(
self
,
*
exc
):
pass
def
close
(
self
):
pass
def
__await__
(
self
):
pass
coro
=
Coro
()
self
.
assertTrue
(
asyncio
.
iscoroutine
(
coro
))
self
.
assertEqual
(
coroutines
.
_format_coroutine
(
coro
),
'AAA()'
)
coro
.
__qualname__
=
'BBB'
self
.
assertEqual
(
coroutines
.
_format_coroutine
(
coro
),
'BBB()'
)
coro
.
cr_running
=
True
self
.
assertEqual
(
coroutines
.
_format_coroutine
(
coro
),
'BBB() running'
)
class
TimerTests
(
unittest
.
TestCase
):
...
...
Misc/NEWS
View file @
bc565e3b
...
...
@@ -358,6 +358,8 @@ Library
-
Issue
#
28371
:
Deprecate
passing
asyncio
.
Handles
to
run_in_executor
.
-
Issue
#
28372
:
Fix
asyncio
to
support
formatting
of
non
-
python
coroutines
.
IDLE
----
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment