Question

I am currently developing a simple application in python that connects to a server. At the moment, it's single-threaded (as multithreading is not currently required).

However I would like - for debugging, maintenance and such to also be able to have a REPL via stdin.

How do I go about that, if possible? Will I need to keep anything in mind? Will I have to make a separate thread for it?

Was it helpful?

Solution

Maybe this question could help. You can modify it a bit to create a customized REPL.

OTHER TIPS

You either need to go non-blocking or use a thread.

I would personally use Twisted for concurrency, which also offers a REPL-protocol which is easy to integrate.

There's also rfoo. From the README:

rconsole - included with rfoo package is a remote Python console with auto completion, which can be used to inspect and modify namespace of a running script.

To activate in a script do:

from rfoo.utils import rconsole
rconsole.spawn_server()

To attach from a shell do:

$ rconsole

SECURITY NOTE:
The rconsole listener started with spawn_server() will accept any local connection and may therefore be insecure to use in shared hosting or similar environments!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top