Martin Panter added the comment:

I recently created Issue 26720 about a similar situation with BufferedWriter. 
However I am starting to believe that the problem cannot be solved the way I 
originally wanted. Instead, the best solution there would be similar what I 
would suggest here: we need to avoid the user accessing the memoryview after 
readinto() or write() has returned. Some ideas, not all perfect:

1. Call memoryview.release() after the method returns. This would be simple and 
practical, but could be cheated by making a second memoryview of the original. 
Also, memoryview.release() is not guaranteed to succeed; there is code that 
raises BufferError("memoryview has exported buffers").

2. Raise an exception (BufferError or RuntimeError?) if readinto() or write() 
returns and the memoryview(s) are not all released. This doesn’t prevent a 
determined programmer from overwriting memory or losing written data, but it 
might let them know about the problem when it happens.

3. Try to force the memoryview.release() state on all views into the original 
memory. Is this practical? I guess this would be a bit inconsistent if some 
other thread was in the middle of a system call using the buffer at the time 
that we want to do the release.

----------
versions: +Python 2.7, Python 3.5, Python 3.6 -Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue15994>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to