Are There High-Level Libraries for Persisted Subinterpreters?

0
6
Asked By TechSavvy42 On

I'm curious if there are any high-level libraries available that can help manage persisted subinterpreters within a single process. My goal is to load a complex series of classes into a subinterpreter that remains active, allowing me to send commands to it from the main interpreter. Ideally, I want something where the subinterpreter isn't constantly being destroyed and recreated.

3 Answers

Answered By DevExplorer123 On

Are you sure you actually need a subinterpreter? You might find multi-threading or multi-processing code could achieve the same results for you.

TechSavvy42 -

I'm open to other suggestions! I initially chose subinterpreters to avoid IPC/pickling overhead with multiprocessing, but I’d look into persisted subprocesses if they’re supported better. Switching to a free-threading version would be ideal, but some libraries I use won't support that just yet. Thanks for your thoughts!

Answered By SmartyPantsDev On

What do you mean by "persisted" subinterpreter? Generally speaking, subinterpreters don't have strong support since they're not much more advantageous than using subprocesses. For instance, libraries built with pyo3, like Pydantic, usually refuse to work in a subinterpreter.

TechSavvy42 -

By persisted, I mean I want to reuse the subinterpreter instance without it being destroyed and re-initialized. I thought subinterpreters were lighter compared to subprocesses? My workload is quite light per thread, but it will be quite frequent.

Answered By CodeWhisperer99 On

You should check out `anyio`, which has built-in support for subinterpreters. Its documentation has some useful insights on how to get started!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.