Search code examples
python-3.xserversimplehttpserverpython-interactive

Run Python process in background with interactive shell on the same memory


I'm not sure if this is the right way to word this, but I have a python web server that accepts connections and updates objects, is it possible to use the interactive shell to inject commands into the same memory space and view/change the objects the server is interacting with?

Currently, once the httpd function starts, it the shell takes no input until the process is interrupted, then I can type and check the object states. But while I'm doing this, the server is not running, and has to be restarted.

Is what I'm trying to do ridiculous or possible? It's primarily for ease of testing and development. I've considered pickling and opening those pickles in another shell.


Solution

  • You could add a (testing only!) route in your web server, like POST /eval, which takes a string which will be Python code, executes it, and returns the result.

    Obviously you need to make sure such functionality isn't exposed to a public network.