5

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?

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

+1: twisted also offers the manhole - a service where you can SSH to your application and get a REPL to interact with it while it is running!
I'm going to give this a go. Sounds like what I need.
2

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!

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.