forpy
forpy copied to clipboard
Support for multiple interpreters?
It might be nice to add support for multiple interpreters (using Py_NewInterpreter()
, Py_EndInterpreter()
, etc.)
Thanks for the suggestion, it is certainly something to consider. Do you have an application, where sub-interpreter support would be useful right now? In my opinion, threading support should be implemented before sub-interpreters. I think I'll look into threading in the nearer future, but before I can do that, there are some smaller enhancements I want to make (documentation, some ndarray methods, iterators).
Yes, my application is this: an interactive Fortran program that has the feature of allowing a user to write and load their own Python plugins to do specific things. Each plugin needs to be independent and not interfere with the others (since any number can be loaded at the same time). So, my thought was that the main program spawns off a new interpreter when a plugin is loaded and uses it for that plugin (and destroys it when the plugin is unloaded). The main program manages the loading/unloading/calling of each plugin, and they would all be completely independent of each other.
As a proof of concept, you could try to call the necessary C API functions (Py_NewInterpreter()
,...) directly.
One questions is, whether numpy
plays nicely with subinterpreters. I don't know what the status is on that, but there seem to be problems:
https://github.com/numpy/numpy/issues/665 which references https://mail.scipy.org/pipermail/numpy-discussion/2009-July/044046.html or https://github.com/numpy/numpy/issues/3961 https://docs.python.org/3.6/c-api/init.html#bugs-and-caveats