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
175421b5
Kaydet (Commit)
175421b5
authored
Şub 23, 2019
tarafından
Pablo Galindo
Kaydeden (comit)
Inada Naoki
Şub 23, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
bpo-36016: Add generation option to gc.getobjects() (GH-11909)
üst
df5cdc11
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
112 additions
and
14 deletions
+112
-14
gc.rst
Doc/library/gc.rst
+5
-2
3.8.rst
Doc/whatsnew/3.8.rst
+9
-0
test_gc.py
Lib/test/test_gc.py
+32
-0
2019-02-17-20-23-54.bpo-36016.5Hns-f.rst
...ore and Builtins/2019-02-17-20-23-54.bpo-36016.5Hns-f.rst
+2
-0
gcmodule.c.h
Modules/clinic/gcmodule.c.h
+25
-7
gcmodule.c
Modules/gcmodule.c
+39
-5
No files found.
Doc/library/gc.rst
Dosyayı görüntüle @
175421b5
...
...
@@ -63,11 +63,14 @@ The :mod:`gc` module provides the following functions:
Return the debugging flags currently set.
.. function:: get_objects()
.. function:: get_objects(
generation=None
)
Returns a list of all objects tracked by the collector, excluding the list
returned.
returned. If *generation* is not None, return only the objects tracked by
the collector that are in that generation.
.. versionchanged:: 3.8
New *generation* parameter.
.. function:: get_stats()
...
...
Doc/whatsnew/3.8.rst
Dosyayı görüntüle @
175421b5
...
...
@@ -163,6 +163,15 @@ gettext
Added :func:`~gettext.pgettext` and its variants.
(Contributed by Franz Glasner, Éric Araujo, and Cheryl Sabella in :issue:`2504`.)
gc
--
:func:`~gc.get_objects` can now receive an optional *generation* parameter
indicating a generation to get objects from. Contributed in
:issue:`36016` by Pablo Galindo.
gzip
----
...
...
Lib/test/test_gc.py
Dosyayı görüntüle @
175421b5
...
...
@@ -766,6 +766,38 @@ class GCTests(unittest.TestCase):
gc
.
unfreeze
()
self
.
assertEqual
(
gc
.
get_freeze_count
(),
0
)
def
test_get_objects
(
self
):
gc
.
collect
()
l
=
[]
l
.
append
(
l
)
self
.
assertIn
(
l
,
gc
.
get_objects
(
generation
=
0
))
self
.
assertNotIn
(
l
,
gc
.
get_objects
(
generation
=
1
))
self
.
assertNotIn
(
l
,
gc
.
get_objects
(
generation
=
2
))
gc
.
collect
(
generation
=
0
)
self
.
assertNotIn
(
l
,
gc
.
get_objects
(
generation
=
0
))
self
.
assertIn
(
l
,
gc
.
get_objects
(
generation
=
1
))
self
.
assertNotIn
(
l
,
gc
.
get_objects
(
generation
=
2
))
gc
.
collect
(
generation
=
1
)
self
.
assertNotIn
(
l
,
gc
.
get_objects
(
generation
=
0
))
self
.
assertNotIn
(
l
,
gc
.
get_objects
(
generation
=
1
))
self
.
assertIn
(
l
,
gc
.
get_objects
(
generation
=
2
))
gc
.
collect
(
generation
=
2
)
self
.
assertNotIn
(
l
,
gc
.
get_objects
(
generation
=
0
))
self
.
assertNotIn
(
l
,
gc
.
get_objects
(
generation
=
1
))
self
.
assertIn
(
l
,
gc
.
get_objects
(
generation
=
2
))
del
l
gc
.
collect
()
def
test_get_objects_arguments
(
self
):
gc
.
collect
()
self
.
assertEqual
(
len
(
gc
.
get_objects
()),
len
(
gc
.
get_objects
(
generation
=
None
)))
self
.
assertRaises
(
ValueError
,
gc
.
get_objects
,
1000
)
self
.
assertRaises
(
ValueError
,
gc
.
get_objects
,
-
1000
)
self
.
assertRaises
(
TypeError
,
gc
.
get_objects
,
"1"
)
self
.
assertRaises
(
TypeError
,
gc
.
get_objects
,
1.234
)
class
GCCallbackTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
...
...
Misc/NEWS.d/next/Core and Builtins/2019-02-17-20-23-54.bpo-36016.5Hns-f.rst
0 → 100644
Dosyayı görüntüle @
175421b5
``gc.get_objects`` can now receive an optional parameter indicating a
generation to get objects from. Patch by Pablo Galindo.
Modules/clinic/gcmodule.c.h
Dosyayı görüntüle @
175421b5
...
...
@@ -216,21 +216,39 @@ gc_get_count(PyObject *module, PyObject *Py_UNUSED(ignored))
}
PyDoc_STRVAR
(
gc_get_objects__doc__
,
"get_objects($module, /)
\n
"
"get_objects($module, /
, generation=None
)
\n
"
"--
\n
"
"
\n
"
"Return a list of objects tracked by the collector (excluding the list returned)."
);
"Return a list of objects tracked by the collector (excluding the list returned).
\n
"
"
\n
"
" generation
\n
"
" Generation to extract the objects from.
\n
"
"
\n
"
"If generation is not None, return only the objects tracked by the collector
\n
"
"that are in that generation."
);
#define GC_GET_OBJECTS_METHODDEF \
{"get_objects", (PyCFunction)
gc_get_objects, METH_NOARG
S, gc_get_objects__doc__},
{"get_objects", (PyCFunction)
(void(*)(void))gc_get_objects, METH_FASTCALL|METH_KEYWORD
S, gc_get_objects__doc__},
static
PyObject
*
gc_get_objects_impl
(
PyObject
*
module
);
gc_get_objects_impl
(
PyObject
*
module
,
Py_ssize_t
generation
);
static
PyObject
*
gc_get_objects
(
PyObject
*
module
,
PyObject
*
Py_UNUSED
(
ignored
)
)
gc_get_objects
(
PyObject
*
module
,
PyObject
*
const
*
args
,
Py_ssize_t
nargs
,
PyObject
*
kwnames
)
{
return
gc_get_objects_impl
(
module
);
PyObject
*
return_value
=
NULL
;
static
const
char
*
const
_keywords
[]
=
{
"generation"
,
NULL
};
static
_PyArg_Parser
_parser
=
{
"|O&:get_objects"
,
_keywords
,
0
};
Py_ssize_t
generation
=
-
1
;
if
(
!
_PyArg_ParseStackAndKeywords
(
args
,
nargs
,
kwnames
,
&
_parser
,
_Py_convert_optional_to_ssize_t
,
&
generation
))
{
goto
exit
;
}
return_value
=
gc_get_objects_impl
(
module
,
generation
);
exit:
return
return_value
;
}
PyDoc_STRVAR
(
gc_get_stats__doc__
,
...
...
@@ -331,4 +349,4 @@ gc_get_freeze_count(PyObject *module, PyObject *Py_UNUSED(ignored))
exit:
return
return_value
;
}
/*[clinic end generated code: output=
5aa5fdc259503d5f
input=a9049054013a1b77]*/
/*[clinic end generated code: output=
d692bf475f0bb096
input=a9049054013a1b77]*/
Modules/gcmodule.c
Dosyayı görüntüle @
175421b5
...
...
@@ -1502,27 +1502,61 @@ gc_get_referents(PyObject *self, PyObject *args)
/*[clinic input]
gc.get_objects
generation: Py_ssize_t(accept={int, NoneType}, c_default="-1") = None
Generation to extract the objects from.
Return a list of objects tracked by the collector (excluding the list returned).
If generation is not None, return only the objects tracked by the collector
that are in that generation.
[clinic start generated code]*/
static
PyObject
*
gc_get_objects_impl
(
PyObject
*
module
)
/*[clinic end generated code: output=
fcb95d2e23e1f750 input=9439fe8170bf35d8
]*/
gc_get_objects_impl
(
PyObject
*
module
,
Py_ssize_t
generation
)
/*[clinic end generated code: output=
48b35fea4ba6cb0e input=ef7da9df9806754c
]*/
{
int
i
;
PyObject
*
result
;
result
=
PyList_New
(
0
);
if
(
result
==
NULL
)
if
(
result
==
NULL
)
{
return
NULL
;
}
/* If generation is passed, we extract only that generation */
if
(
generation
!=
-
1
)
{
if
(
generation
>=
NUM_GENERATIONS
)
{
PyErr_Format
(
PyExc_ValueError
,
"generation parameter must be less than the number of "
"available generations (%i)"
,
NUM_GENERATIONS
);
goto
error
;
}
if
(
generation
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"generation parameter cannot be negative"
);
goto
error
;
}
if
(
append_objects
(
result
,
GEN_HEAD
(
generation
)))
{
goto
error
;
}
return
result
;
}
/* If generation is not passed or None, get all objects from all generations */
for
(
i
=
0
;
i
<
NUM_GENERATIONS
;
i
++
)
{
if
(
append_objects
(
result
,
GEN_HEAD
(
i
)))
{
Py_DECREF
(
result
);
return
NULL
;
goto
error
;
}
}
return
result
;
error:
Py_DECREF
(
result
);
return
NULL
;
}
/*[clinic input]
...
...
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