The second _io_BufferedWriter_write_impl call is for show warning like "ResourceWarning: unclosed file <_io.BufferedRandom name='myfile'>"
Try `f.close()`, or `with open(...)`. On Thu, May 30, 2019 at 12:03 PM Windson Yang <wiwind...@gmail.com> wrote: > > My script looks like this: > > f = open('myfile', 'a+b') > f.write(b'abcde') > > And I also add a `printf` statement in the _io_BufferedWriter_write_impl > <https://github.com/python/cpython/blob/ada319bb6d0ebcc68d3e0ef2b4279ea061877ac8/Modules/_io/bufferedio.c#L1910> > function. > > static PyObject * _io_BufferedWriter_write_impl(buffered *self, > Py_buffer *buffer) > /*[clinic end generated code: output=7f8d1365759bfc6b > input=dd87dd85fc7f8850]*/ > { > printf("call write_impl\n"); > PyObject *res = NULL; > Py_ssize_t written, avail, remaining; > Py_off_t offset; > ... > > After I compiled then run my script. I found _io_BufferedWriter_write_impl > <https://github.com/python/cpython/blob/ada319bb6d0ebcc68d3e0ef2b4279ea061877ac8/Modules/_io/bufferedio.c#L1910> > had > been called twice which I expected only once. The second time it changed > self->pos to an unexpected value too. > -- > https://mail.python.org/mailman/listinfo/python-list -- Inada Naoki <songofaca...@gmail.com> -- https://mail.python.org/mailman/listinfo/python-list