Attaching to a Python Interpreter a la Tcl

Discussion in 'Python' started by DE, Feb 23, 2005.

  1. DE

    DE Guest

    Hello,

    Some long time ago, I used to use Tcl/Tk. I had an tcl embedded into my
    app.

    The coolest thing was however, I was able to attach to the interpreter
    (built in to my app) via a tcl shell in which I could type in regular
    tcl code which would be interpreted by the interpreter of my
    application. Naturally, it was possible to call tcl functions of my
    applications.

    Some kind of rapid RPC.

    Is this also possible with python ?

    Thanks,
    DE, Feb 23, 2005
    #1
    1. Advertising

  2. DE

    Robin Becker Guest

    DE wrote:
    > Hello,
    >
    > Some long time ago, I used to use Tcl/Tk. I had an tcl embedded into my
    > app.
    >
    > The coolest thing was however, I was able to attach to the interpreter
    > (built in to my app) via a tcl shell in which I could type in regular
    > tcl code which would be interpreted by the interpreter of my
    > application. Naturally, it was possible to call tcl functions of my
    > applications.
    >
    > Some kind of rapid RPC.
    >
    > Is this also possible with python ?
    >
    > Thanks,
    >

    I think you are talking about the tk send command which allows for
    communicating with a known app.

    I don't believe python comes with such a facility without some coding,
    but it has been implemented in various ways using sockets etc etc.

    I seem to remember that modern idle uses an rpc technique for debugging.

    There are several python projects which address interprocess
    communication pyro http://pyro.sourceforge.net/ is a good example.
    --
    Robin Becker
    Robin Becker, Feb 23, 2005
    #2
    1. Advertising

  3. DE

    Fuzzyman Guest

    Fuzzyman, Feb 23, 2005
    #3
  4. DE

    Ville Vainio Guest

    >>>>> "fuzzyman" == Fuzzyman <> writes:

    fuzzyman> Do you mean making the interpreter available from within
    fuzzyman> a Python app ? There are various ways of doing that -
    fuzzyman> you can see the SPE editor which uses pycrust as one
    fuzzyman> example. http://spe.pycs.net

    I believe he means embedding he interpreter in his app, then accessing
    the interpreter from another process - so you could change and view
    global vars of the running process from the interpreter, for
    example. This basically means redirecting i/o of the interpreter to a
    socket to which you connect via, say, telnet. There are libs that do
    such a thing, I even remember trying one out myself, but I couldn't
    find it quickly enough from google.

    --
    Ville Vainio http://tinyurl.com/2prnb
    Ville Vainio, Feb 23, 2005
    #4
  5. In article <>,
    Robin Becker <> wrote:
    >DE wrote:
    >> Hello,
    >>
    >> Some long time ago, I used to use Tcl/Tk. I had an tcl embedded into my
    >> app.
    >>
    >> The coolest thing was however, I was able to attach to the interpreter
    >> (built in to my app) via a tcl shell in which I could type in regular
    >> tcl code which would be interpreted by the interpreter of my
    >> application. Naturally, it was possible to call tcl functions of my
    >> applications.
    >>
    >> Some kind of rapid RPC.
    >>
    >> Is this also possible with python ?
    >>
    >> Thanks,
    >>

    >I think you are talking about the tk send command which allows for
    >communicating with a known app.
    >
    >I don't believe python comes with such a facility without some coding,
    >but it has been implemented in various ways using sockets etc etc.
    >
    >I seem to remember that modern idle uses an rpc technique for debugging.
    >
    >There are several python projects which address interprocess
    >communication pyro http://pyro.sourceforge.net/ is a good example.

    .
    .
    .
    Agreed: Python makes it easy to do this. Tk *does* this,
    out-of-the-box.

    But note! Tkinter can access Tk's [send], so, if the appli-
    cation happened to be built with Tkinter, and one were fluent
    enough at translating between Tcl and Python to reach the
    latter by way of the former, then, yes, you would find that
    your Python application already has this.
    Cameron Laird, Feb 24, 2005
    #5
  6. On 23 Feb 2005 02:37:48 -0800, DE <> wrote:
    > Hello,
    >
    > Some long time ago, I used to use Tcl/Tk. I had an tcl embedded into my
    > app.
    >
    > The coolest thing was however, I was able to attach to the interpreter
    > (built in to my app) via a tcl shell in which I could type in regular
    > tcl code which would be interpreted by the interpreter of my
    > application. Naturally, it was possible to call tcl functions of my
    > applications.
    >
    > Some kind of rapid RPC.
    >
    > Is this also possible with python ?


    Yes, using something like twisted's 'Manhole', which allows you to
    execute code in the server process.

    It may require twisted-ising your application however.

    Stephen
    Stephen Thorne, Feb 24, 2005
    #6
  7. DE

    Jeff Epler Guest

    Cameron Laird mentioned Tk's send working with Python; if you are writing your
    app with Tkinter, here is some code to let you use tcl commands like
    send <appname> python <expression or statement>
    for remote control. You could build a more sophisticated front-end for this,
    and you'll probably also want to add stuff like sending the text of an
    exception as the result of the 'send' command.

    Jeff

    #------------------------------------------------------------------------
    import Tkinter

    __all__ = 'python', 'setup_send'
    def makecommand(master, name, func, subst=None, needcleanup=0):
    f = Tkinter.CallWrapper(func, subst, master).__call__
    master.tk.createcommand(name, f)
    if needcleanup:
    if master._tclCommands is None:
    master._tclCommands = []
    master._tclCommands.append(name)
    return name


    def setup_send(app, ns, name="python"):
    def python(*args):
    s = " ".join(args)
    print args
    try:
    code = compile(s, '<send>', 'eval')
    return eval(code, ns)
    except SyntaxError:
    code = compile(s, '<send>', 'exec')
    exec code in ns
    makecommand(app, name, python)

    if __name__ == '__main__':
    app = Tkinter.Tk()
    setup_send(app, {})
    app.mainloop()
    #------------------------------------------------------------------------

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.6 (GNU/Linux)

    iD8DBQFCHdt7Jd01MZaTXX0RAp0dAKCbVF88J7nEo4Nyg+F06xD5uZhrPgCeIwyz
    HepI83ocgSrW+EoRD/BQ8Vc=
    =vBV2
    -----END PGP SIGNATURE-----
    Jeff Epler, Feb 24, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David  Swedish

    Compile problem with TCL interpreter

    David Swedish, Feb 6, 2004, in forum: C++
    Replies:
    1
    Views:
    1,189
  2. Kannon
    Replies:
    0
    Views:
    221
    Kannon
    Jan 13, 2009
  3. Mark Wilson
    Replies:
    0
    Views:
    94
    Mark Wilson
    Aug 24, 2003
  4. Mumia W.

    Inline::Tcl vs. Inline::Tcl

    Mumia W., Aug 23, 2006, in forum: Perl Misc
    Replies:
    0
    Views:
    138
    Mumia W.
    Aug 23, 2006
  5. Filippo

    drive externally a tcl interpreter

    Filippo, Sep 26, 2006, in forum: Perl Misc
    Replies:
    1
    Views:
    91
    Ben Morrow
    Sep 26, 2006
Loading...

Share This Page