[issue9757] Add context manager protocol to memoryviews

Antoine Pitrou report at bugs.python.org
Tue Sep 7 17:56:27 CEST 2010

Antoine Pitrou <pitrou at free.fr> added the comment:

> Given this explanation, of course I am +1 on an explicit release()
> method.  But I'm still skeptical that a context manager adds much (not
> sure if that counts as -0 or +0 :-).

Ok, release() is probably enough.

> I suppose after release() is called all accesses through the
> memoryview object should be invalid, right?

Indeed. The patch tests for that (it uses "with" to release the
memoryview, but it wouldn't be hard to change it for a release()

> Is this not covered by PEP 3118 at all?

The PEP says “this memory view object holds on to the memory of base
[i.e. the object the buffer was acquired from] until it is deleted”.
Apparently issues pertaining to delayed garbage collection weren't
raised at the time.


Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list