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
416c1ebd
Unverified
Kaydet (Commit)
416c1ebd
authored
May 28, 2018
tarafından
Yury Selivanov
Kaydeden (comit)
GitHub
May 28, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-32610: Fix asyncio.all_tasks() to return only pending tasks. (GH-7174)
üst
fdccfe09
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
9 deletions
+51
-9
asyncio-task.rst
Doc/library/asyncio-task.rst
+5
-2
__init__.py
Lib/asyncio/__init__.py
+4
-0
runners.py
Lib/asyncio/runners.py
+1
-2
tasks.py
Lib/asyncio/tasks.py
+11
-1
test_tasks.py
Lib/test/test_asyncio/test_tasks.py
+27
-2
2018-05-28-16-40-32.bpo-32610.KvUAsL.rst
...S.d/next/Library/2018-05-28-16-40-32.bpo-32610.KvUAsL.rst
+1
-0
_asynciomodule.c
Modules/_asynciomodule.c
+2
-2
No files found.
Doc/library/asyncio-task.rst
Dosyayı görüntüle @
416c1ebd
...
...
@@ -443,6 +443,8 @@ Task
Return a set of all tasks for an event loop.
By default all tasks for the current event loop are returned.
If *loop* is ``None``, :func:`get_event_loop` function
is used to get the current loop.
.. classmethod:: current_task(loop=None)
...
...
@@ -567,8 +569,9 @@ Task functions
Return a set of :class:`Task` objects created for the loop.
If *loop* is ``None`` :func:`get_event_loop` is used for getting
current loop.
If *loop* is ``None``, :func:`get_running_loop` is used for getting
current loop (contrary to the deprecated :meth:`Task.all_tasks` method
that uses :func:`get_event_loop`.)
.. versionadded:: 3.7
...
...
Lib/asyncio/__init__.py
Dosyayı görüntüle @
416c1ebd
...
...
@@ -18,6 +18,10 @@ from .subprocess import *
from
.tasks
import
*
from
.transports
import
*
# Exposed for _asynciomodule.c to implement now deprecated
# Task.all_tasks() method. This function will be removed in 3.9.
from
.tasks
import
_all_tasks_compat
# NoQA
__all__
=
(
base_events
.
__all__
+
coroutines
.
__all__
+
events
.
__all__
+
...
...
Lib/asyncio/runners.py
Dosyayı görüntüle @
416c1ebd
...
...
@@ -51,8 +51,7 @@ def run(main, *, debug=False):
def
_cancel_all_tasks
(
loop
):
to_cancel
=
[
task
for
task
in
tasks
.
all_tasks
(
loop
)
if
not
task
.
done
()]
to_cancel
=
tasks
.
all_tasks
(
loop
)
if
not
to_cancel
:
return
...
...
Lib/asyncio/tasks.py
Dosyayı görüntüle @
416c1ebd
...
...
@@ -33,6 +33,16 @@ def current_task(loop=None):
def
all_tasks
(
loop
=
None
):
"""Return a set of all tasks for the loop."""
if
loop
is
None
:
loop
=
events
.
get_running_loop
()
return
{
t
for
t
in
_all_tasks
if
futures
.
_get_loop
(
t
)
is
loop
and
not
t
.
done
()}
def
_all_tasks_compat
(
loop
=
None
):
# Different from "all_task()" by returning *all* Tasks, including
# the completed ones. Used to implement deprecated "Tasks.all_task()"
# method.
if
loop
is
None
:
loop
=
events
.
get_event_loop
()
return
{
t
for
t
in
_all_tasks
if
futures
.
_get_loop
(
t
)
is
loop
}
...
...
@@ -82,7 +92,7 @@ class Task(futures._PyFuture): # Inherit Python Task implementation
"use asyncio.all_tasks() instead"
,
PendingDeprecationWarning
,
stacklevel
=
2
)
return
all_tasks
(
loop
)
return
_all_tasks_compat
(
loop
)
def
__init__
(
self
,
coro
,
*
,
loop
=
None
):
super
()
.
__init__
(
loop
=
loop
)
...
...
Lib/test/test_asyncio/test_tasks.py
Dosyayı görüntüle @
416c1ebd
...
...
@@ -1897,8 +1897,10 @@ class BaseTaskTests:
# See http://bugs.python.org/issue29271 for details:
asyncio
.
set_event_loop
(
self
.
loop
)
try
:
self
.
assertEqual
(
asyncio
.
all_tasks
(),
{
task
})
self
.
assertEqual
(
asyncio
.
all_tasks
(
None
),
{
task
})
with
self
.
assertWarns
(
PendingDeprecationWarning
):
self
.
assertEqual
(
Task
.
all_tasks
(),
{
task
})
with
self
.
assertWarns
(
PendingDeprecationWarning
):
self
.
assertEqual
(
Task
.
all_tasks
(
None
),
{
task
})
finally
:
asyncio
.
set_event_loop
(
None
)
...
...
@@ -2483,6 +2485,9 @@ class BaseTaskIntrospectionTests:
def
_loop
(
self
):
return
loop
def
done
(
self
):
return
False
task
=
TaskLike
()
loop
=
mock
.
Mock
()
...
...
@@ -2496,6 +2501,9 @@ class BaseTaskIntrospectionTests:
def
get_loop
(
self
):
return
loop
def
done
(
self
):
return
False
task
=
TaskLike
()
loop
=
mock
.
Mock
()
...
...
@@ -2504,6 +2512,23 @@ class BaseTaskIntrospectionTests:
self
.
assertEqual
(
asyncio
.
all_tasks
(
loop
),
{
task
})
self
.
_unregister_task
(
task
)
def
test__register_task_3
(
self
):
class
TaskLike
:
def
get_loop
(
self
):
return
loop
def
done
(
self
):
return
True
task
=
TaskLike
()
loop
=
mock
.
Mock
()
self
.
assertEqual
(
asyncio
.
all_tasks
(
loop
),
set
())
self
.
_register_task
(
task
)
self
.
assertEqual
(
asyncio
.
all_tasks
(
loop
),
set
())
self
.
assertEqual
(
asyncio
.
Task
.
all_tasks
(
loop
),
{
task
})
self
.
_unregister_task
(
task
)
def
test__enter_task
(
self
):
task
=
mock
.
Mock
()
loop
=
mock
.
Mock
()
...
...
Misc/NEWS.d/next/Library/2018-05-28-16-40-32.bpo-32610.KvUAsL.rst
0 → 100644
Dosyayı görüntüle @
416c1ebd
Make asyncio.all_tasks() return only pending tasks.
Modules/_asynciomodule.c
Dosyayı görüntüle @
416c1ebd
...
...
@@ -11,7 +11,7 @@ module _asyncio
/* identifiers used from some functions */
_Py_IDENTIFIER
(
__asyncio_running_event_loop__
);
_Py_IDENTIFIER
(
add_done_callback
);
_Py_IDENTIFIER
(
all_tasks
);
_Py_IDENTIFIER
(
_all_tasks_compat
);
_Py_IDENTIFIER
(
call_soon
);
_Py_IDENTIFIER
(
cancel
);
_Py_IDENTIFIER
(
current_task
);
...
...
@@ -2125,7 +2125,7 @@ _asyncio_Task_all_tasks_impl(PyTypeObject *type, PyObject *loop)
return
NULL
;
}
all_tasks_func
=
_PyObject_GetAttrId
(
asyncio_mod
,
&
PyId_
all_tasks
);
all_tasks_func
=
_PyObject_GetAttrId
(
asyncio_mod
,
&
PyId_
_all_tasks_compat
);
if
(
all_tasks_func
==
NULL
)
{
return
NULL
;
}
...
...
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