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
c880ffe7
Kaydet (Commit)
c880ffe7
authored
Eki 09, 2018
tarafından
twisteroid ambassador
Kaydeden (comit)
Yury Selivanov
Eki 09, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-34769: Thread safety for _asyncgen_finalizer_hook(). (GH-9716)
üst
79d21331
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
4 deletions
+71
-4
base_events.py
Lib/asyncio/base_events.py
+1
-4
test_base_events.py
Lib/test/test_asyncio/test_base_events.py
+68
-0
2018-10-09-11-01-16.bpo-34769.cSkkZt.rst
...S.d/next/Library/2018-10-09-11-01-16.bpo-34769.cSkkZt.rst
+2
-0
No files found.
Lib/asyncio/base_events.py
Dosyayı görüntüle @
c880ffe7
...
...
@@ -477,10 +477,7 @@ class BaseEventLoop(events.AbstractEventLoop):
def
_asyncgen_finalizer_hook
(
self
,
agen
):
self
.
_asyncgens
.
discard
(
agen
)
if
not
self
.
is_closed
():
self
.
create_task
(
agen
.
aclose
())
# Wake up the loop if the finalizer was called from
# a different thread.
self
.
_write_to_self
()
self
.
call_soon_threadsafe
(
self
.
create_task
,
agen
.
aclose
())
def
_asyncgen_firstiter_hook
(
self
,
agen
):
if
self
.
_asyncgens_shutdown_called
:
...
...
Lib/test/test_asyncio/test_base_events.py
Dosyayı görüntüle @
c880ffe7
...
...
@@ -926,6 +926,74 @@ class BaseEventLoopTests(test_utils.TestCase):
self
.
loop
.
run_forever
()
self
.
loop
.
_selector
.
select
.
assert_called_once_with
(
0
)
async
def
leave_unfinalized_asyncgen
(
self
):
# Create an async generator, iterate it partially, and leave it
# to be garbage collected.
# Used in async generator finalization tests.
# Depends on implementation details of garbage collector. Changes
# in gc may break this function.
status
=
{
'started'
:
False
,
'stopped'
:
False
,
'finalized'
:
False
}
async
def
agen
():
status
[
'started'
]
=
True
try
:
for
item
in
[
'ZERO'
,
'ONE'
,
'TWO'
,
'THREE'
,
'FOUR'
]:
yield
item
finally
:
status
[
'finalized'
]
=
True
ag
=
agen
()
ai
=
ag
.
__aiter__
()
async
def
iter_one
():
try
:
item
=
await
ai
.
__anext__
()
except
StopAsyncIteration
:
return
if
item
==
'THREE'
:
status
[
'stopped'
]
=
True
return
asyncio
.
create_task
(
iter_one
())
asyncio
.
create_task
(
iter_one
())
return
status
def
test_asyncgen_finalization_by_gc
(
self
):
# Async generators should be finalized when garbage collected.
self
.
loop
.
_process_events
=
mock
.
Mock
()
self
.
loop
.
_write_to_self
=
mock
.
Mock
()
with
support
.
disable_gc
():
status
=
self
.
loop
.
run_until_complete
(
self
.
leave_unfinalized_asyncgen
())
while
not
status
[
'stopped'
]:
test_utils
.
run_briefly
(
self
.
loop
)
self
.
assertTrue
(
status
[
'started'
])
self
.
assertTrue
(
status
[
'stopped'
])
self
.
assertFalse
(
status
[
'finalized'
])
support
.
gc_collect
()
test_utils
.
run_briefly
(
self
.
loop
)
self
.
assertTrue
(
status
[
'finalized'
])
def
test_asyncgen_finalization_by_gc_in_other_thread
(
self
):
# Python issue 34769: If garbage collector runs in another
# thread, async generators will not finalize in debug
# mode.
self
.
loop
.
_process_events
=
mock
.
Mock
()
self
.
loop
.
_write_to_self
=
mock
.
Mock
()
self
.
loop
.
set_debug
(
True
)
with
support
.
disable_gc
():
status
=
self
.
loop
.
run_until_complete
(
self
.
leave_unfinalized_asyncgen
())
while
not
status
[
'stopped'
]:
test_utils
.
run_briefly
(
self
.
loop
)
self
.
assertTrue
(
status
[
'started'
])
self
.
assertTrue
(
status
[
'stopped'
])
self
.
assertFalse
(
status
[
'finalized'
])
self
.
loop
.
run_until_complete
(
self
.
loop
.
run_in_executor
(
None
,
support
.
gc_collect
))
test_utils
.
run_briefly
(
self
.
loop
)
self
.
assertTrue
(
status
[
'finalized'
])
class
MyProto
(
asyncio
.
Protocol
):
done
=
None
...
...
Misc/NEWS.d/next/Library/2018-10-09-11-01-16.bpo-34769.cSkkZt.rst
0 → 100644
Dosyayı görüntüle @
c880ffe7
Fix for async generators not finalizing when event loop is in debug mode and
garbage collector runs in another thread.
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