Debugging pipe IPC
Jim B. Wilson
wilson at afn.org
Thu Dec 20 10:12:36 EST 2007
Ian Clark wrote:
> import os
> os.system("netcat -l -p 1234 localhost")
>
> HTH,
Nope, but the network theme got me thinking about how one might run
Python on a remote host. After a few false starts, Googling "remote
python shell" led me to Guido's "ripshell.py" (not *that* Guido, a
different one). Peeking inside, I discovered the module I'm looking for
was "code". Remember, in my case, communication on stdin and stdout
was all handled by a Pyrex extension. I'm unsure the code below will
work in a pure Python application.
For posterity, here is itest.py, the solution to my problem:
### itest.py - allows interactive debugging of a "filter"
#
# If stdin and stdout are dedicated to your filter script, but you
# want to interactively check a few things, try something like this:
from code import interact
import sys
sys.stdout = open("/dev/tty", "w") # Rebind Python's lips
sys.stdin = open("/dev/tty", "r") # and Python's ears.
foo = "This is a test" # Lay down some history
interact( # Convenience function from code.
"At your service, Sir!", # BUG: could be "Madam" or "Miss"
local = locals()) # Teach interpreter some history
print "Thank you, Sir!" # BUG: ibid.
To check this works:
$ python itest.py </dev/null >/dev/full # mother is a deafmute
At your service, Sir!
>>> foo
'This is a test'
>>> ^D (not shown)
Thank you, Sir!
$
More information about the Python-list
mailing list