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
7408da54
Kaydet (Commit)
7408da54
authored
Eki 26, 2001
tarafından
Fred Drake
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Many, many small fixes and improvements, most suggested by Detlef Lannert.
üst
c44e9eca
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
17 deletions
+27
-17
libweakref.tex
Doc/lib/libweakref.tex
+27
-17
No files found.
Doc/lib/libweakref.tex
Dosyayı görüntüle @
7408da54
...
@@ -14,6 +14,9 @@
...
@@ -14,6 +14,9 @@
The
\module
{
weakref
}
module allows the Python programmer to create
The
\module
{
weakref
}
module allows the Python programmer to create
\dfn
{
weak references
}
to objects.
\dfn
{
weak references
}
to objects.
In the discussion which follows, the term
\dfn
{
referent
}
means the
object which is referred to by a weak reference.
XXX --- need to say more here!
XXX --- need to say more here!
Not all objects can be weakly referenced; those objects which do
Not all objects can be weakly referenced; those objects which do
...
@@ -24,12 +27,13 @@ be made to support weak references; see section \ref{weakref-extension},
...
@@ -24,12 +27,13 @@ be made to support weak references; see section \ref{weakref-extension},
\begin{funcdesc}
{
ref
}{
object
\optional
{
, callback
}}
\begin{funcdesc}
{
ref
}{
object
\optional
{
, callback
}}
Return a weak reference to
\var
{
object
}
. If
\var
{
callback
}
is
Return a weak reference to
\var
{
object
}
. The original object can be
retrieved by calling the reference object if the referent is still
alive; if the referent is no longer alive, calling the reference
object will cause
\code
{
None
}
to be returned. If
\var
{
callback
}
is
provided, it will be called when the object is about to be
provided, it will be called when the object is about to be
finalized; the weak reference object will be passed as the only
finalized; the weak reference object will be passed as the only
parameter to the callback; the referent will no longer be available.
parameter to the callback; the referent will no longer be available.
The original object can be retrieved by calling the reference
object, if the referent is still alive.
It is allowable for many weak references to be constructed for the
It is allowable for many weak references to be constructed for the
same object. Callbacks registered for each weak reference will be
same object. Callbacks registered for each weak reference will be
...
@@ -48,10 +52,11 @@ be made to support weak references; see section \ref{weakref-extension},
...
@@ -48,10 +52,11 @@ be made to support weak references; see section \ref{weakref-extension},
\exception
{
TypeError
}
.
\exception
{
TypeError
}
.
Weak references support tests for equality, but not ordering. If
Weak references support tests for equality, but not ordering. If
the
\var
{
object
}
is still alive, two references are equal if the
the referents are still alive, two references have the same
objects are equal (regardless of the
\var
{
callback
}
). If
equalality relationship as their referents (regardless of the
\var
{
object
}
has been deleted, they are equal only if the references
\var
{
callback
}
). If either referent has been deleted, the
being compared are the same reference object.
references are equal only if the reference objects are the same
object.
\end{funcdesc}
\end{funcdesc}
\begin{funcdesc}
{
proxy
}{
object
\optional
{
, callback
}}
\begin{funcdesc}
{
proxy
}{
object
\optional
{
, callback
}}
...
@@ -89,7 +94,7 @@ be made to support weak references; see section \ref{weakref-extension},
...
@@ -89,7 +94,7 @@ be made to support weak references; see section \ref{weakref-extension},
\begin{classdesc}
{
WeakValueDictionary
}{
\optional
{
dict
}}
\begin{classdesc}
{
WeakValueDictionary
}{
\optional
{
dict
}}
Mapping class that references values weakly. Entries in the
Mapping class that references values weakly. Entries in the
dictionary will be discarded when no strong reference to the value
dictionary will be discarded when no strong reference to the value
exists anymore.
exists any
more.
\end{classdesc}
\end{classdesc}
\begin{datadesc}
{
ReferenceType
}
\begin{datadesc}
{
ReferenceType
}
...
@@ -158,7 +163,8 @@ application code that needs to use a reference object should follow
...
@@ -158,7 +163,8 @@ application code that needs to use a reference object should follow
this pattern:
this pattern:
\begin{verbatim}
\begin{verbatim}
o = ref()
# r is a weak reference object
o = r()
if o is None:
if o is None:
# referent has been garbage collected
# referent has been garbage collected
print "Object has been allocated; can't frobnicate."
print "Object has been allocated; can't frobnicate."
...
@@ -169,7 +175,7 @@ else:
...
@@ -169,7 +175,7 @@ else:
Using a separate test for ``liveness'' creates race conditions in
Using a separate test for ``liveness'' creates race conditions in
threaded applications; another thread can cause a weak reference to
threaded applications; another thread can cause a weak reference to
become invalidated before the
\method
{
get()
}
method
is called; the
become invalidated before the
weak reference
is called; the
idiom shown above is safe in threaded applications as well as
idiom shown above is safe in threaded applications as well as
single-threaded applications.
single-threaded applications.
...
@@ -189,10 +195,12 @@ import weakref
...
@@ -189,10 +195,12 @@ import weakref
_
id2obj
_
dict = weakref.WeakValueDictionary()
_
id2obj
_
dict = weakref.WeakValueDictionary()
def remember(obj):
def remember(obj):
_
id2obj
_
dict[id(obj)] = obj
oid = id(obj)
_
id2obj
_
dict[oid] = obj
return oid
def id2obj(id):
def id2obj(
o
id):
return
_
id2obj
_
dict
(id)
return
_
id2obj
_
dict
[oid]
\end{verbatim}
\end{verbatim}
...
@@ -205,7 +213,7 @@ overhead on those objects which do not benefit by weak referencing
...
@@ -205,7 +213,7 @@ overhead on those objects which do not benefit by weak referencing
(such as numbers).
(such as numbers).
For an object to be weakly referencable, the extension must include a
For an object to be weakly referencable, the extension must include a
\ctype
{
PyObject
*
}
field in the instance structure for the use of the
\ctype
{
PyObject*
}
field in the instance structure for the use of the
weak reference mechanism; it must be initialized to
\NULL
{}
by the
weak reference mechanism; it must be initialized to
\NULL
{}
by the
object's constructor. It must also set the
\member
{
tp
_
weaklistoffset
}
object's constructor. It must also set the
\member
{
tp
_
weaklistoffset
}
field of the corresponding type object to the offset of the field.
field of the corresponding type object to the offset of the field.
...
@@ -236,17 +244,19 @@ PyTypeObject PyInstance_Type = {
...
@@ -236,17 +244,19 @@ PyTypeObject PyInstance_Type = {
The only further addition is that the destructor needs to call the
The only further addition is that the destructor needs to call the
weak reference manager to clear any weak references. This should be
weak reference manager to clear any weak references. This should be
done before any other parts of the destruction have occurred:
done before any other parts of the destruction have occurred, but is
only required if the weak reference list is non-
\NULL
:
\begin{verbatim}
\begin{verbatim}
static void
static void
instance
_
dealloc(PyInstanceObject *inst)
instance
_
dealloc(PyInstanceObject *inst)
{
{
/* Allocate tempories if needed, but do not begin
/* Allocate tempor
ar
ies if needed, but do not begin
destruction just yet.
destruction just yet.
*/
*/
PyObject
_
ClearWeakRefs((PyObject *) inst);
if (inst->in
_
weakreflist != NULL)
PyObject
_
ClearWeakRefs((PyObject *) inst);
/* Proceed with object destruction normally. */
/* Proceed with object destruction normally. */
}
}
...
...
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