This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: memoryview should be a context manager
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.4
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: pitrou, serhiy.storchaka, skrah, vstinner
Priority: normal Keywords: easy

Created on 2013-10-20 21:00 by serhiy.storchaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg200633 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-10-20 21:00
memoryview() acquires resource but it rarely released explicitly. I propose to made memoryview a context manager which calls the release() method in the __exit__() method. Perhaps it worth also add resource warning in the __del__() method if a memoryview was not released.
msg200635 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-10-20 21:02
Already proposed in issue9757.
msg200664 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2013-10-21 00:12
> Already proposed in issue9757.

Well, it was not only proposed, but it was also implemented (by Antoine).

Python 3.4.0a3+ (default:84a8b797c5c5+, Oct 20 2013, 16:02:32) 
[GCC 4.8.1 20130603 (Red Hat 4.8.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x=memoryview(b'abc')
>>> with x: pass
>>> bytes(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: operation forbidden on released memoryview object
msg200709 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-10-21 07:53
> Well, it was not only proposed, but it was also implemented (by Antoine).

Oh, sorry for the noise.
msg200710 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-10-21 07:53
And thank you Antoine for this.
Date User Action Args
2022-04-11 14:57:52adminsetgithub: 63520
2013-10-21 07:53:33serhiy.storchakasetmessages: + msg200710
2013-10-21 07:53:12serhiy.storchakasetstatus: open -> closed
resolution: out of date
messages: + msg200709

stage: needs patch -> resolved
2013-10-21 00:13:00vstinnersetmessages: + msg200664
2013-10-21 00:11:09vstinnersetnosy: + vstinner
2013-10-20 21:02:42pitrousetmessages: + msg200635
2013-10-20 21:01:31serhiy.storchakasetnosy: + pitrou, skrah
2013-10-20 21:00:32serhiy.storchakacreate