Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
43d71e25
Kaydet (Commit)
43d71e25
authored
Eki 02, 2015
tarafından
Yury Selivanov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
asyncio: Make ensure_future() accept all kinds of awaitables.
üst
987f2151
620279b9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
41 additions
and
2 deletions
+41
-2
3.5.rst
Doc/whatsnew/3.5.rst
+7
-0
tasks.py
Lib/asyncio/tasks.py
+14
-2
test_tasks.py
Lib/test/test_asyncio/test_tasks.py
+18
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/whatsnew/3.5.rst
Dosyayı görüntüle @
43d71e25
...
...
@@ -803,6 +803,13 @@ Notable changes in the :mod:`asyncio` module since Python 3.4.0:
:class:`asyncio.Queue` class.
(Contributed by Victor Stinner.)
Updates in 3.5.1:
* The :func:`~asyncio.ensure_future` function and all functions that
use it, such as :meth:`loop.run_until_complete() <asyncio.BaseEventLoop.run_until_complete>`,
now accept all kinds of :term:`awaitable objects <awaitable>`.
(Contributed by Yury Selivanov.)
bz2
---
...
...
Lib/asyncio/tasks.py
Dosyayı görüntüle @
43d71e25
...
...
@@ -512,7 +512,7 @@ def async(coro_or_future, *, loop=None):
def
ensure_future
(
coro_or_future
,
*
,
loop
=
None
):
"""Wrap a coroutine in a future.
"""Wrap a coroutine
or an awaitable
in a future.
If the argument is a Future, it is returned directly.
"""
...
...
@@ -527,8 +527,20 @@ def ensure_future(coro_or_future, *, loop=None):
if
task
.
_source_traceback
:
del
task
.
_source_traceback
[
-
1
]
return
task
elif
compat
.
PY35
and
inspect
.
isawaitable
(
coro_or_future
):
return
ensure_future
(
_wrap_awaitable
(
coro_or_future
),
loop
=
loop
)
else
:
raise
TypeError
(
'A Future or coroutine is required'
)
raise
TypeError
(
'A Future, a coroutine or an awaitable is required'
)
@coroutine
def
_wrap_awaitable
(
awaitable
):
"""Helper for asyncio.ensure_future().
Wraps awaitable (an object with __await__) into a coroutine
that will later be wrapped in a Task by ensure_future().
"""
return
(
yield
from
awaitable
.
__await__
())
class
_GatheringFuture
(
futures
.
Future
):
...
...
Lib/test/test_asyncio/test_tasks.py
Dosyayı görüntüle @
43d71e25
...
...
@@ -153,6 +153,24 @@ class TaskTests(test_utils.TestCase):
t
=
asyncio
.
ensure_future
(
t_orig
,
loop
=
self
.
loop
)
self
.
assertIs
(
t
,
t_orig
)
@unittest.skipUnless
(
PY35
,
'need python 3.5 or later'
)
def
test_ensure_future_awaitable
(
self
):
class
Aw
:
def
__init__
(
self
,
coro
):
self
.
coro
=
coro
def
__await__
(
self
):
return
(
yield
from
self
.
coro
)
@asyncio.coroutine
def
coro
():
return
'ok'
loop
=
asyncio
.
new_event_loop
()
self
.
set_event_loop
(
loop
)
fut
=
asyncio
.
ensure_future
(
Aw
(
coro
()),
loop
=
loop
)
loop
.
run_until_complete
(
fut
)
assert
fut
.
result
()
==
'ok'
def
test_ensure_future_neither
(
self
):
with
self
.
assertRaises
(
TypeError
):
asyncio
.
ensure_future
(
'ok'
)
...
...
Misc/NEWS
Dosyayı görüntüle @
43d71e25
...
...
@@ -152,6 +152,8 @@ Library
- Issue #23572: Fixed functools.singledispatch on classes with falsy
metaclasses. Patch by Ethan Furman.
- asyncio: ensure_future() now accepts awaitable objects.
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