Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactoring into C library + Python interface? #2296

Closed
stevengj opened this issue Aug 16, 2023 · 2 comments
Closed

refactoring into C library + Python interface? #2296

stevengj opened this issue Aug 16, 2023 · 2 comments

Comments

@stevengj
Copy link

stevengj commented Aug 16, 2023

It would be nice to be able to use this from other languages, such as Julia, without requiring a Python dependency. Since the core functionality here is already implemented in C, would you ever consider refactoring it into a Python-independent C library + a Python interface, so that non-Python languages could call the C library directly?

I realize that this is a nontrivial amount of work because currently your C code is intertwined with calls to libpython, but it seems (at first glance) like something that would be doable in a week or two. (Or is there some major obstacle I'm missing?) I'd be willing to help, but only if this is something that would interest you.

@giampaolo
Copy link
Owner

giampaolo commented Aug 16, 2023

it seems (at first glance) like something that would be doable in a week or two

I think you are seriously underestimating how big of an effort that would be. :) It's not only about making the C extensions return generic C types instead of Python types (there's a Java lib called cigar which does this), but also providing decent support support for those languages: redesigning APIs, documenting them, writing tests for those languages, add CI, (possibly) distribute binaries etc.

Above all: be ready to handle and keep up with the new influx of bug reports and PRs, which considering psutil's numbers are probably gonna be a lot.

Another thing to consider is that a rewrite of that size would almost certainly introduce regressions to the existing 15+ years old Python implementation, especially on Linux (which is the major platform), since the parsing of /proc would have to be rewritten from scratch in C.

It's not something I never thought about doing (I did), but I know it would end up being a full-time job in the literal sense, which would also probably require a team of people.

@stevengj
Copy link
Author

stevengj commented Aug 16, 2023

but also providing decent support support for those languages: redesigning APIs, documenting them, writing wrappers for those languages, unit tests, add CI, (possibly) distribute binaries etc.

I was thinking of just refactoring psutils to have a C-callable API, and then adding a Julia interface. Other languages would be on their own to add a wrapper.

since the parsing of /proc would have to be rewritten from scratch in C.

Ah, I see, I thought everything for Linux was in _psutil_linux.c, but now I see that you have a ton of stuff in _pslinux.py etc. that would be a pain to rewrite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants