[issue26720] memoryview from BufferedWriter becomes garbage

2016-04-18 Thread Martin Panter
Martin Panter added the comment: Closing this as a duplicate of Issue 15994, where I have proposed a patch to add a note for RawIOBase.write(), and call memoryview.release() when the method returns. -- resolution: -> duplicate status: open -> closed superseder: -> memoryview to

[issue26720] memoryview from BufferedWriter becomes garbage

2016-04-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Python implementation passes bytearray to underlying write and delete it's content just after that. Thus saving written data was never worked, and making it working don't worth efforts. I agree with you, we should add a warning against saving. This might be

[issue26720] memoryview from BufferedWriter becomes garbage

2016-04-12 Thread Martin Panter
Martin Panter added the comment: The trouble with my original idea is that it is complex to implement, and inconsistent. If you wrote small amounts to your BufferedWriter, you would get a memoryview of bytes that you save for later. If there was a write of a large bytes object, we could pass

[issue26720] memoryview from BufferedWriter becomes garbage

2016-04-12 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I meant getting rid of memoryview at all and passing bytes buffer object directly to underlying write. But now I see that this idea perhaps is not feasible since we must write not only from the start of the buffer. A writer like AuditableBytesIO is very

[issue26720] memoryview from BufferedWriter becomes garbage

2016-04-12 Thread Martin Panter
Martin Panter added the comment: I realize there is another problem, and doing tricks with a bytes object won’t help that. BufferedWriter bypasses its own buffer for large writes: >>> writer = BufferedWriter(Raw()) >>> large = bytearray(1) >>> writer.write(large) 1 >>>

[issue26720] memoryview from BufferedWriter becomes garbage

2016-04-11 Thread Martin Panter
Martin Panter added the comment: To create a memoryview with unlimited lifetime, I understand we need to nominate an “exporting object”, which becomes memoryview.obj. Using a bytes object here might be the simplest fix for just BufferedWriter. However it looks like the buffer is shared with

[issue26720] memoryview from BufferedWriter becomes garbage

2016-04-09 Thread Martin Panter
Martin Panter added the comment: On further thought, I think releasing the buffer would not be the best long-term solution. I encountered this bug when wrapping custom AuditableBytesIO objects (Lib/test/test_httpservers.py) with BufferedWriter, where the raw object just saves each write()

[issue26720] memoryview from BufferedWriter becomes garbage

2016-04-09 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Another option is to use the bytes object as internal buffer. If its refcount is == 1 (normal case), it is modified in-place, otherwise (if the reference is saved outside) new bytes object is created. -- ___

[issue26720] memoryview from BufferedWriter becomes garbage

2016-04-09 Thread Serhiy Storchaka
Changes by Serhiy Storchaka : -- nosy: +benjamin.peterson, pitrou, serhiy.storchaka, stutzbach ___ Python tracker ___

[issue26720] memoryview from BufferedWriter becomes garbage

2016-04-09 Thread Martin Panter
New submission from Martin Panter: >>> class Raw(RawIOBase): ... def writable(self): return True ... def write(self, b): ... global written ... written = b ... return len(b) ... >>> writer = BufferedWriter(Raw()) >>> writer.write(b"blaua") 5 >>> raw =