Question on multiple Python users in one application

Chris Angelico rosuav at gmail.com
Thu Oct 6 21:48:43 EDT 2016


On Fri, Oct 7, 2016 at 12:21 PM, Loren Wilton <myspamacct at earthlink.net> wrote:
> The VM is a program running on Windows. The mainframe object code is just
> byte code. The VM has routines to handle every operator and each kind of
> Descriptor that they might validly use. One form of Descriptor is only used
> by the CALL instruction. It allows an "internal call" to a procedure that is
> part of the VM.  Assuming that the VM linked to CPython, I could use one
> form of this to pass a text line to PyRun_SimpleString. Then I cna write a
> trivial program that will read from a terminal file and pass any received
> text to SimpleString, and somehow route any response back to the terminal
> file.

The source code for SimpleString looks like this:

int
PyRun_SimpleStringFlags(const char *command, PyCompilerFlags *flags)
{
    PyObject *m, *d, *v;
    m = PyImport_AddModule("__main__");
    if (m == NULL)
        return -1;
    d = PyModule_GetDict(m);
    v = PyRun_StringFlags(command, Py_file_input, d, d, flags);
    if (v == NULL) {
        PyErr_Print();
        return -1;
    }
    Py_DECREF(v);
    return 0;
}

If that had been your original plan, it's dead simple to enhance it to
use per-user module names. Just do this same work, but substitute a
different module name right at the beginning! Other
extremely-high-level interface functions are similar. You should have
no trouble making this embed work; and then it's just a matter of
figuring out the bridge code between that and the rest of the VM.

(Okay, so it's probably not going to be as easy as that made it sound,
but still. Definitely plausible.)

ChrisA



More information about the Python-list mailing list