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
5d7e3b6c
Kaydet (Commit)
5d7e3b6c
authored
Kas 17, 2015
tarafından
Yury Selivanov
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
asyncio: Cleanup Future API
See
https://github.com/python/asyncio/pull/292
for details.
üst
0013cced
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
40 deletions
+49
-40
futures.py
Lib/asyncio/futures.py
+30
-30
proactor_events.py
Lib/asyncio/proactor_events.py
+2
-1
selector_events.py
Lib/asyncio/selector_events.py
+4
-2
tasks.py
Lib/asyncio/tasks.py
+2
-1
unix_events.py
Lib/asyncio/unix_events.py
+4
-2
test_futures.py
Lib/test/test_asyncio/test_futures.py
+7
-4
No files found.
Lib/asyncio/futures.py
Dosyayı görüntüle @
5d7e3b6c
...
...
@@ -154,7 +154,7 @@ class Future:
if
self
.
_loop
.
get_debug
():
self
.
_source_traceback
=
traceback
.
extract_stack
(
sys
.
_getframe
(
1
))
def
_format_callbacks
(
self
):
def
_
_
format_callbacks
(
self
):
cb
=
self
.
_callbacks
size
=
len
(
cb
)
if
not
size
:
...
...
@@ -184,7 +184,7 @@ class Future:
result
=
reprlib
.
repr
(
self
.
_result
)
info
.
append
(
'result={}'
.
format
(
result
))
if
self
.
_callbacks
:
info
.
append
(
self
.
_format_callbacks
())
info
.
append
(
self
.
_
_
format_callbacks
())
if
self
.
_source_traceback
:
frame
=
self
.
_source_traceback
[
-
1
]
info
.
append
(
'created at
%
s:
%
s'
%
(
frame
[
0
],
frame
[
1
]))
...
...
@@ -319,12 +319,6 @@ class Future:
# So-called internal methods (note: no set_running_or_notify_cancel()).
def
_set_result_unless_cancelled
(
self
,
result
):
"""Helper setting the result only if the future was not cancelled."""
if
self
.
cancelled
():
return
self
.
set_result
(
result
)
def
set_result
(
self
,
result
):
"""Mark the future done and set its result.
...
...
@@ -358,27 +352,6 @@ class Future:
# have had a chance to call result() or exception().
self
.
_loop
.
call_soon
(
self
.
_tb_logger
.
activate
)
# Truly internal methods.
def
_copy_state
(
self
,
other
):
"""Internal helper to copy state from another Future.
The other Future may be a concurrent.futures.Future.
"""
assert
other
.
done
()
if
self
.
cancelled
():
return
assert
not
self
.
done
()
if
other
.
cancelled
():
self
.
cancel
()
else
:
exception
=
other
.
exception
()
if
exception
is
not
None
:
self
.
set_exception
(
exception
)
else
:
result
=
other
.
result
()
self
.
set_result
(
result
)
def
__iter__
(
self
):
if
not
self
.
done
():
self
.
_blocking
=
True
...
...
@@ -390,6 +363,13 @@ class Future:
__await__
=
__iter__
# make compatible with 'await' expression
def
_set_result_unless_cancelled
(
fut
,
result
):
"""Helper setting the result only if the future was not cancelled."""
if
fut
.
cancelled
():
return
fut
.
set_result
(
result
)
def
_set_concurrent_future_state
(
concurrent
,
source
):
"""Copy state from a future to a concurrent.futures.Future."""
assert
source
.
done
()
...
...
@@ -405,6 +385,26 @@ def _set_concurrent_future_state(concurrent, source):
concurrent
.
set_result
(
result
)
def
_copy_future_state
(
source
,
dest
):
"""Internal helper to copy state from another Future.
The other Future may be a concurrent.futures.Future.
"""
assert
source
.
done
()
if
dest
.
cancelled
():
return
assert
not
dest
.
done
()
if
source
.
cancelled
():
dest
.
cancel
()
else
:
exception
=
source
.
exception
()
if
exception
is
not
None
:
dest
.
set_exception
(
exception
)
else
:
result
=
source
.
result
()
dest
.
set_result
(
result
)
def
_chain_future
(
source
,
destination
):
"""Chain two futures so that when one completes, so does the other.
...
...
@@ -421,7 +421,7 @@ def _chain_future(source, destination):
def
_set_state
(
future
,
other
):
if
isinstance
(
future
,
Future
):
future
.
_copy_state
(
other
)
_copy_future_state
(
other
,
future
)
else
:
_set_concurrent_future_state
(
future
,
other
)
...
...
Lib/asyncio/proactor_events.py
Dosyayı görüntüle @
5d7e3b6c
...
...
@@ -41,7 +41,8 @@ class _ProactorBasePipeTransport(transports._FlowControlMixin,
self
.
_loop
.
call_soon
(
self
.
_protocol
.
connection_made
,
self
)
if
waiter
is
not
None
:
# only wake up the waiter when connection_made() has been called
self
.
_loop
.
call_soon
(
waiter
.
_set_result_unless_cancelled
,
None
)
self
.
_loop
.
call_soon
(
futures
.
_set_result_unless_cancelled
,
waiter
,
None
)
def
__repr__
(
self
):
info
=
[
self
.
__class__
.
__name__
]
...
...
Lib/asyncio/selector_events.py
Dosyayı görüntüle @
5d7e3b6c
...
...
@@ -636,7 +636,8 @@ class _SelectorSocketTransport(_SelectorTransport):
self
.
_sock_fd
,
self
.
_read_ready
)
if
waiter
is
not
None
:
# only wake up the waiter when connection_made() has been called
self
.
_loop
.
call_soon
(
waiter
.
_set_result_unless_cancelled
,
None
)
self
.
_loop
.
call_soon
(
futures
.
_set_result_unless_cancelled
,
waiter
,
None
)
def
pause_reading
(
self
):
if
self
.
_closing
:
...
...
@@ -990,7 +991,8 @@ class _SelectorDatagramTransport(_SelectorTransport):
self
.
_sock_fd
,
self
.
_read_ready
)
if
waiter
is
not
None
:
# only wake up the waiter when connection_made() has been called
self
.
_loop
.
call_soon
(
waiter
.
_set_result_unless_cancelled
,
None
)
self
.
_loop
.
call_soon
(
futures
.
_set_result_unless_cancelled
,
waiter
,
None
)
def
get_write_buffer_size
(
self
):
return
sum
(
len
(
data
)
for
data
,
_
in
self
.
_buffer
)
...
...
Lib/asyncio/tasks.py
Dosyayı görüntüle @
5d7e3b6c
...
...
@@ -500,7 +500,8 @@ def sleep(delay, result=None, *, loop=None):
future
=
futures
.
Future
(
loop
=
loop
)
h
=
future
.
_loop
.
call_later
(
delay
,
future
.
_set_result_unless_cancelled
,
result
)
futures
.
_set_result_unless_cancelled
,
future
,
result
)
try
:
return
(
yield
from
future
)
finally
:
...
...
Lib/asyncio/unix_events.py
Dosyayı görüntüle @
5d7e3b6c
...
...
@@ -319,7 +319,8 @@ class _UnixReadPipeTransport(transports.ReadTransport):
self
.
_fileno
,
self
.
_read_ready
)
if
waiter
is
not
None
:
# only wake up the waiter when connection_made() has been called
self
.
_loop
.
call_soon
(
waiter
.
_set_result_unless_cancelled
,
None
)
self
.
_loop
.
call_soon
(
futures
.
_set_result_unless_cancelled
,
waiter
,
None
)
def
__repr__
(
self
):
info
=
[
self
.
__class__
.
__name__
]
...
...
@@ -442,7 +443,8 @@ class _UnixWritePipeTransport(transports._FlowControlMixin,
if
waiter
is
not
None
:
# only wake up the waiter when connection_made() has been called
self
.
_loop
.
call_soon
(
waiter
.
_set_result_unless_cancelled
,
None
)
self
.
_loop
.
call_soon
(
futures
.
_set_result_unless_cancelled
,
waiter
,
None
)
def
__repr__
(
self
):
info
=
[
self
.
__class__
.
__name__
]
...
...
Lib/test/test_asyncio/test_futures.py
Dosyayı görüntüle @
5d7e3b6c
...
...
@@ -174,11 +174,13 @@ class FutureTests(test_utils.TestCase):
'<Future cancelled>'
)
def
test_copy_state
(
self
):
from
asyncio.futures
import
_copy_future_state
f
=
asyncio
.
Future
(
loop
=
self
.
loop
)
f
.
set_result
(
10
)
newf
=
asyncio
.
Future
(
loop
=
self
.
loop
)
newf
.
_copy_state
(
f
)
_copy_future_state
(
f
,
new
f
)
self
.
assertTrue
(
newf
.
done
())
self
.
assertEqual
(
newf
.
result
(),
10
)
...
...
@@ -186,7 +188,7 @@ class FutureTests(test_utils.TestCase):
f_exception
.
set_exception
(
RuntimeError
())
newf_exception
=
asyncio
.
Future
(
loop
=
self
.
loop
)
newf_exception
.
_copy_state
(
f_exception
)
_copy_future_state
(
f_exception
,
new
f_exception
)
self
.
assertTrue
(
newf_exception
.
done
())
self
.
assertRaises
(
RuntimeError
,
newf_exception
.
result
)
...
...
@@ -194,7 +196,7 @@ class FutureTests(test_utils.TestCase):
f_cancelled
.
cancel
()
newf_cancelled
=
asyncio
.
Future
(
loop
=
self
.
loop
)
newf_cancelled
.
_copy_state
(
f_cancelled
)
_copy_future_state
(
f_cancelled
,
new
f_cancelled
)
self
.
assertTrue
(
newf_cancelled
.
cancelled
())
def
test_iter
(
self
):
...
...
@@ -382,9 +384,10 @@ class FutureTests(test_utils.TestCase):
self
.
check_future_exception_never_retrieved
(
True
)
def
test_set_result_unless_cancelled
(
self
):
from
asyncio
import
futures
fut
=
asyncio
.
Future
(
loop
=
self
.
loop
)
fut
.
cancel
()
fut
.
_set_result_unless_cancelled
(
2
)
fut
ures
.
_set_result_unless_cancelled
(
fut
,
2
)
self
.
assertTrue
(
fut
.
cancelled
())
...
...
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