

Interactive shell to a running Python process - daenz
https://github.com/amoffat/Inspect-Shell

======
albertzeyer
If you want to do the same without modifying the script (or if you have the
script already running without the needed import for the remote debugging
possibility), i.e. inject into a running process:

<https://github.com/albertz/pydbattach>

------
swdunlop
I use ipython's "ipdb" or plain old Python "pdb" for the same functionality,
and a bit more -- people don't seem to realize that ipdb gives them a full-on
REPL within the calling context.

I usually wrap it into our error logging functions, so an environment variable
enables debugging where I would normally have a catch-all -- very handy when
looking for heisenbugs in AndBug.

AntiLog -- <https://gist.github.com/a256ed1295619fad7cfc>

AndBug -- <https://github.com/swdunlop/andbug>

------
cmsj
My most excellent friend Thomas Hurst implemented a remote python shell a few
years ago, for use in debugging running instances of Terminator. You can see
the code in question here:

[http://bazaar.launchpad.net/~gnome-
terminator/terminator/tru...](http://bazaar.launchpad.net/~gnome-
terminator/terminator/trunk/view/head:/terminatorlib/debugserver.py)

and how it gets set up, starting at line 88, here:

[http://bazaar.launchpad.net/~gnome-
terminator/terminator/tru...](http://bazaar.launchpad.net/~gnome-
terminator/terminator/trunk/view/head:/terminator#L88)

------
Peaker
You can also run an RPyC* server in your process, and connect to it from any
Python shell on any computer to control it.

* <http://rpyc.sourceforge.net/>

------
storborg
Would it be possible to use gdb or something similar to inject this into a
running process?

~~~
jeremya
Yes, pyrasite does just that with a python wrapper around the gdb commands.

<https://fedorahosted.org/pyrasite/>

It was discussed here:

<http://news.ycombinator.com/item?id=3014484>

------
teyc
Zope has this facility and boy it was useful for troubleshooting live systems.

~~~
kra
And Twisted has Manhole, but for some reason we were never allowed to enable
it on production deployments...

------
thelastnode
What are the consequences of running this in production? What's the
performance hit like, is it unsafe, etc.?

~~~
masklinn
> is it unsafe, etc.?

As the readme notes, it's completely unsafe if you perform any mutation
operation.

As to the performance hit, I'd expect almost none when not in use for long-
running processes: it spawns a thread, and that thread will then wait on a
socket accept, no connection, no resources spent. You'll still be paying in
memory for the server thread, but that's it (the server thread only creates
two objects, an rlcompleter.Completer instance and a function).

------
politician
I wanted something like this back in the day to be able to poke around in the
EVE Online client. Nice job!

------
jphackworth
Very interesting. I would love to see this for other programming languages,
especially Ruby (probably fairly easy) or Objective-C (may be quite hard).

~~~
albertzeyer
For ObjC:

<https://github.com/albertz/Pyjector> (and then access the ObjC runtime via
the Python ObjC bridge)

<https://github.com/albertz/FScriptAnywhereSIMBL>

~~~
saurik
Or Cycript, which all of us iOS hackers use. ;P

<http://www.cycript.org/> <http://iphonedevwiki.net/index.php/Cycript>

------
sidharth
This is great I thought Ipython was great. But this is awesome.

