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
d08c363c
Kaydet (Commit)
d08c363c
authored
May 13, 2015
tarafından
Yury Selivanov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Sync asyncio code from default branch.
üst
3a81f9ba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
55 deletions
+67
-55
locks.py
Lib/asyncio/locks.py
+53
-55
streams.py
Lib/asyncio/streams.py
+14
-0
No files found.
Lib/asyncio/locks.py
Dosyayı görüntüle @
d08c363c
...
...
@@ -3,12 +3,16 @@
__all__
=
[
'Lock'
,
'Event'
,
'Condition'
,
'Semaphore'
,
'BoundedSemaphore'
]
import
collections
import
sys
from
.
import
events
from
.
import
futures
from
.coroutines
import
coroutine
_PY35
=
sys
.
version_info
>=
(
3
,
5
)
class
_ContextManager
:
"""Context manager.
...
...
@@ -39,7 +43,53 @@ class _ContextManager:
self
.
_lock
=
None
# Crudely prevent reuse.
class
Lock
:
class
_ContextManagerMixin
:
def
__enter__
(
self
):
raise
RuntimeError
(
'"yield from" should be used as context manager expression'
)
def
__exit__
(
self
,
*
args
):
# This must exist because __enter__ exists, even though that
# always raises; that's how the with-statement works.
pass
@coroutine
def
__iter__
(
self
):
# This is not a coroutine. It is meant to enable the idiom:
#
# with (yield from lock):
# <block>
#
# as an alternative to:
#
# yield from lock.acquire()
# try:
# <block>
# finally:
# lock.release()
yield
from
self
.
acquire
()
return
_ContextManager
(
self
)
if
_PY35
:
def
__await__
(
self
):
# To make "with await lock" work.
yield
from
self
.
acquire
()
return
_ContextManager
(
self
)
@coroutine
def
__aenter__
(
self
):
yield
from
self
.
acquire
()
# We have no use for the "as ..." clause in the with
# statement for locks.
return
None
@coroutine
def
__aexit__
(
self
,
exc_type
,
exc
,
tb
):
self
.
release
()
class
Lock
(
_ContextManagerMixin
):
"""Primitive lock objects.
A primitive lock is a synchronization primitive that is not owned
...
...
@@ -153,32 +203,6 @@ class Lock:
else
:
raise
RuntimeError
(
'Lock is not acquired.'
)
def
__enter__
(
self
):
raise
RuntimeError
(
'"yield from" should be used as context manager expression'
)
def
__exit__
(
self
,
*
args
):
# This must exist because __enter__ exists, even though that
# always raises; that's how the with-statement works.
pass
@coroutine
def
__iter__
(
self
):
# This is not a coroutine. It is meant to enable the idiom:
#
# with (yield from lock):
# <block>
#
# as an alternative to:
#
# yield from lock.acquire()
# try:
# <block>
# finally:
# lock.release()
yield
from
self
.
acquire
()
return
_ContextManager
(
self
)
class
Event
:
"""Asynchronous equivalent to threading.Event.
...
...
@@ -246,7 +270,7 @@ class Event:
self
.
_waiters
.
remove
(
fut
)
class
Condition
:
class
Condition
(
_ContextManagerMixin
)
:
"""Asynchronous equivalent to threading.Condition.
This class implements condition variable objects. A condition variable
...
...
@@ -356,21 +380,8 @@ class Condition:
"""
self
.
notify
(
len
(
self
.
_waiters
))
def
__enter__
(
self
):
raise
RuntimeError
(
'"yield from" should be used as context manager expression'
)
def
__exit__
(
self
,
*
args
):
pass
@coroutine
def
__iter__
(
self
):
# See comment in Lock.__iter__().
yield
from
self
.
acquire
()
return
_ContextManager
(
self
)
class
Semaphore
:
class
Semaphore
(
_ContextManagerMixin
):
"""A Semaphore implementation.
A semaphore manages an internal counter which is decremented by each
...
...
@@ -441,19 +452,6 @@ class Semaphore:
waiter
.
set_result
(
True
)
break
def
__enter__
(
self
):
raise
RuntimeError
(
'"yield from" should be used as context manager expression'
)
def
__exit__
(
self
,
*
args
):
pass
@coroutine
def
__iter__
(
self
):
# See comment in Lock.__iter__().
yield
from
self
.
acquire
()
return
_ContextManager
(
self
)
class
BoundedSemaphore
(
Semaphore
):
"""A bounded semaphore implementation.
...
...
Lib/asyncio/streams.py
Dosyayı görüntüle @
d08c363c
...
...
@@ -6,6 +6,7 @@ __all__ = ['StreamReader', 'StreamWriter', 'StreamReaderProtocol',
]
import
socket
import
sys
if
hasattr
(
socket
,
'AF_UNIX'
):
__all__
.
extend
([
'open_unix_connection'
,
'start_unix_server'
])
...
...
@@ -19,6 +20,7 @@ from .log import logger
_DEFAULT_LIMIT
=
2
**
16
_PY35
=
sys
.
version_info
>=
(
3
,
5
)
class
IncompleteReadError
(
EOFError
):
...
...
@@ -485,3 +487,15 @@ class StreamReader:
n
-=
len
(
block
)
return
b
''
.
join
(
blocks
)
if
_PY35
:
@coroutine
def
__aiter__
(
self
):
return
self
@coroutine
def
__anext__
(
self
):
val
=
yield
from
self
.
readline
()
if
val
==
b
''
:
raise
StopAsyncIteration
return
val
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