Is there a way to attach a python shell to a running process? I saw something similar for ruby but could not find a python equivalent.
Is there a way to attach a python shell to a running process? I saw something similar for ruby but could not find a python equivalent.
Here is how I launch a shell for my projects (it tries to use IPython, if it isn't working it uses code.interact): http://paste.plurk.com/show/17110/
There are also macros for gdb floating around -- you can attach the gdb (C etc.) debugger to a python process and then examine the stack through some gdb macros, but the interactivity is limited (unless perhaps someone has built it up more). That lets you break in at any moment. See http://wiki.python.org/moin/DebuggingWithGdb
In many cases where a production process is doing mysterious things, using strace or perhaps ltrace on it can give a good hint to what it is doing, together with lsof to see what files it's reading/writing.
http://github.com/cool-RR/PythonTurtle/
Check out the directory "/src/shelltoprocess".
It's a package for connecting a GUI shell, running on wxPython, to a Python process spawned by the multiprocessing package. It's documented and MIT-licensed.