Author skrah
Recipients Thomas.Waldmann, skrah, xtreak
Date 2019-01-08.19:35:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1546976130.47.0.432543270001.issue35686@roundup.psfhosted.org>
In-reply-to
Content
Well, the problem in b) is that data[:2] creates a new memoryview,
so the underlying ManagedBufferObject now has two exports:

  - One from the context manager.

  - The second from the slice.

So memoryview.__exit__() decrements on export, but the second one
is hanging.

This actually works as expected because the ManagedBufferObject
cannot know that it could also release the slice. That's what I
meant by saying that it's the application's responsibility to
release all views that are based on the context manager's view.


One way of doing so would be this:

with open(fn, 'rb') as fd:
    with mmap.mmap(fd.fileno(), 0, access=mmap.ACCESS_READ) as mm:
        with memoryview(mm) as data:
            with data[:2] as theslice:
                print(theslice)
History
Date User Action Args
2019-01-08 19:35:32skrahsetrecipients: + skrah, Thomas.Waldmann, xtreak
2019-01-08 19:35:30skrahsetmessageid: <1546976130.47.0.432543270001.issue35686@roundup.psfhosted.org>
2019-01-08 19:35:30skrahlinkissue35686 messages
2019-01-08 19:35:30skrahcreate