最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

rpy2 - KeyError in _rinterface_capi.py - Stack Overflow

programmeradmin2浏览0评论

I've been using rpy2 for several years without issue. All of a sudden, it occasionally throws a KeyError in rpy2/rinterface_lib/_rinterface_capi.py, line 71, in the _release method:

69 def _release(cdata: FFI.CData) -> None:
70   addr = int(ffi.cast('uintptr_t', cdata))
71   count = _R_PRESERVED[addr] - 1

This is not reliably reproduceable, and happens maybe 5% of the time. I have to admit that I don't know enough about the internals of how rpy2 is working to understand beyond this.

Should that line be changed to use get() instead or would that result in a memory leak?

Thanks!

I've been using rpy2 for several years without issue. All of a sudden, it occasionally throws a KeyError in rpy2/rinterface_lib/_rinterface_capi.py, line 71, in the _release method:

69 def _release(cdata: FFI.CData) -> None:
70   addr = int(ffi.cast('uintptr_t', cdata))
71   count = _R_PRESERVED[addr] - 1

This is not reliably reproduceable, and happens maybe 5% of the time. I have to admit that I don't know enough about the internals of how rpy2 is working to understand beyond this.

Should that line be changed to use get() instead or would that result in a memory leak?

Thanks!

Share Improve this question edited Mar 14 at 17:59 Jes Lefcourt asked Mar 14 at 16:38 Jes LefcourtJes Lefcourt 11 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 0

That code handle reference counting in Python for R objects. In a nutshell, this is part of code that keeps track of R objects we want to protect from deletion on the R side. For example, if we have an rpy2 proxy to an R object visible to Python but would otherwise think that it is no longer needed and can be garbage collected. The error is that when trying to decrease the reference count of the object it is not (no longer presumably) known to Python.

That error should definitely not happen. At the moment, the only cases I can think of would be:
- multithreading in Python with multiple references to the same rpy2 objects created/deleted and interruptions interfering with the reference counting code.
- moving R objects (that should never happened - at least was not possible for R when this was written)

Can you open an issue on the rpy2 issue tracker on GitHub?

发布评论

评论列表(0)

  1. 暂无评论