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
dfbd27f0
Kaydet (Commit)
dfbd27f0
authored
Haz 24, 2015
tarafından
Yury Selivanov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
asyncio: Merge changes from issue #24400.
üst
6bc217dd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
31 deletions
+17
-31
coroutines.py
Lib/asyncio/coroutines.py
+17
-31
No files found.
Lib/asyncio/coroutines.py
Dosyayı görüntüle @
dfbd27f0
...
...
@@ -34,30 +34,20 @@ _DEBUG = (not sys.flags.ignore_environment
try
:
types
.
coroutine
_types_coroutine
=
types
.
coroutine
except
AttributeError
:
native_coroutine_support
=
False
else
:
native_coroutine_support
=
True
_types_coroutine
=
None
try
:
_iscoroutinefunction
=
inspect
.
iscoroutinefunction
_i
nspect_i
scoroutinefunction
=
inspect
.
iscoroutinefunction
except
AttributeError
:
_iscoroutinefunction
=
lambda
func
:
False
_i
nspect_i
scoroutinefunction
=
lambda
func
:
False
try
:
inspect
.
CO_COROUTINE
except
AttributeError
:
_is_native_coro_code
=
lambda
code
:
False
else
:
_is_native_coro_code
=
lambda
code
:
(
code
.
co_flags
&
inspect
.
CO_COROUTINE
)
try
:
from
collections.abc
import
Coroutine
as
CoroutineABC
,
\
Awaitable
as
AwaitableABC
from
collections.abc
import
Coroutine
as
_CoroutineABC
,
\
Awaitable
as
_AwaitableABC
except
ImportError
:
CoroutineABC
=
AwaitableABC
=
None
_CoroutineABC
=
_
AwaitableABC
=
None
# Check for CPython issue #21209
...
...
@@ -89,10 +79,7 @@ def debug_wrapper(gen):
# We only wrap here coroutines defined via 'async def' syntax.
# Generator-based coroutines are wrapped in @coroutine
# decorator.
if
_is_native_coro_code
(
gen
.
gi_code
):
return
CoroWrapper
(
gen
,
None
)
else
:
return
gen
return
CoroWrapper
(
gen
,
None
)
class
CoroWrapper
:
...
...
@@ -177,8 +164,7 @@ def coroutine(func):
If the coroutine is not yielded from before it is destroyed,
an error message is logged.
"""
is_coroutine
=
_iscoroutinefunction
(
func
)
if
is_coroutine
and
_is_native_coro_code
(
func
.
__code__
):
if
_inspect_iscoroutinefunction
(
func
):
# In Python 3.5 that's all we need to do for coroutines
# defiend with "async def".
# Wrapping in CoroWrapper will happen via
...
...
@@ -193,7 +179,7 @@ def coroutine(func):
res
=
func
(
*
args
,
**
kw
)
if
isinstance
(
res
,
futures
.
Future
)
or
inspect
.
isgenerator
(
res
):
res
=
yield
from
res
elif
AwaitableABC
is
not
None
:
elif
_
AwaitableABC
is
not
None
:
# If 'func' returns an Awaitable (new in 3.5) we
# want to run it.
try
:
...
...
@@ -201,15 +187,15 @@ def coroutine(func):
except
AttributeError
:
pass
else
:
if
isinstance
(
res
,
AwaitableABC
):
if
isinstance
(
res
,
_
AwaitableABC
):
res
=
yield
from
await_meth
()
return
res
if
not
_DEBUG
:
if
native_coroutine_support
:
wrapper
=
types
.
coroutine
(
coro
)
else
:
if
_types_coroutine
is
None
:
wrapper
=
coro
else
:
wrapper
=
_types_coroutine
(
coro
)
else
:
@functools.wraps
(
func
)
def
wrapper
(
*
args
,
**
kwds
):
...
...
@@ -231,12 +217,12 @@ def coroutine(func):
def
iscoroutinefunction
(
func
):
"""Return True if func is a decorated coroutine function."""
return
(
getattr
(
func
,
'_is_coroutine'
,
False
)
or
_iscoroutinefunction
(
func
))
_i
nspect_i
scoroutinefunction
(
func
))
_COROUTINE_TYPES
=
(
types
.
GeneratorType
,
CoroWrapper
)
if
CoroutineABC
is
not
None
:
_COROUTINE_TYPES
+=
(
CoroutineABC
,)
if
_
CoroutineABC
is
not
None
:
_COROUTINE_TYPES
+=
(
_
CoroutineABC
,)
def
iscoroutine
(
obj
):
...
...
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