BufferError when using memoryview

See original GitHub issue

I noticed this when trying to use yappi with tornado. Here is a simple repro:

import yappi
yappi.start()


def test_mem():
    buf = bytearray()
    buf += b't' * 200
    view = memoryview(buf)[10:].tobytes()
    del buf[:10]
    return view


if __name__ == "__main__":
    test_mem()

Without yappi, the code completes successfully. With yappi I get the following error:

Traceback (most recent call last):
  File "yappi_repro.py", line 14, in <module>
    test_mem()
  File "yappi_repro.py", line 9, in test_mem
    del buf[:10]
BufferError: Existing exports of data: object cannot be re-sized

Reproducible on python 3.6, 3.7 and 3.8. I have not tried python 2.7

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
coldeasycommented, Sep 23, 2020

Confirmed #61 fixes the issue, thanks @sumerc!

1reaction
coldeasycommented, Sep 21, 2020

That’s great, thanks for being so responsive. I’m happy to test your changes - currently I have this hack in place to unblock my progress

diff --git a/yappi/_yappi.c b/yappi/_yappi.c
index 7d21006..d8ea7f2 100644
--- a/yappi/_yappi.c
+++ b/yappi/_yappi.c
@@ -571,6 +571,11 @@ _ccode2pit(void *cco, uintptr_t current_tag)
         pit->builtin = 1;
         pit->modname = _pycfunction_module_name(cfn);
         pit->lineno = 0;
+       if (cfn->m_self && PyMemoryView_Check(cfn->m_self)) {
+           pit->fn_descriptor = PyStr_FromString("memoryview");
+           pit->name = PyStr_FromString("memoryview");
+           return pit;
+       }
         pit->fn_descriptor = (PyObject *)cfn;
         Py_INCREF(cfn);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Exception Handling - BufferError - Airbrake Blog
The BufferError occurs when a problem arises while working with any sort of memory buffer within Python. Specifically, classes like memoryview ...
Read more >
BufferError: memoryview has 1 exported buffer : PY-54447
Type the following python code and debug it with a breakpoint at the last line: import random from concurrent.futures import wait, ALL_COMPLETED, ...
Read more >
python - Example to throw a BufferError - Stack Overflow
From the 3.3 source code, I see the following error messages being used for BufferError : memoryview : underlying buffer is not writable...
Read more >
Buffers and Memoryview Objects — Python 2.7.2 documentation
These errors should be a BufferError unless there is another error that is actually causing the problem. The exporter can use flags information...
Read more >
Issue 15994: memoryview to freed memory can cause segfault
A memoryview which does not own a reference to its base object can ... coincide with view) view[0] = 0 # overwrite first...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found