Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 18th, 2005, 10:56 PM
DE
Guest
 
Posts: n/a
Default Attaching to a Python Interpreter a la Tcl

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,

  #2  
Old July 18th, 2005, 10:56 PM
Robin Becker
Guest
 
Posts: n/a
Default Re: Attaching to a Python Interpreter a la Tcl

DE wrote:[color=blue]
> 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,
>[/color]
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
  #3  
Old July 18th, 2005, 10:56 PM
Fuzzyman
Guest
 
Posts: n/a
Default Re: Attaching to a Python Interpreter a la Tcl

Do you mean making the interpreter available from within a Python app ?

There are various ways of doing that - you can see the SPE editor which
uses pycrust as one example. http://spe.pycs.net

You could also embed IPython for a good interface to the interpreter.
http://ipython.scipy.net

Regards,


Fuzzy
http://www.voidspace.org.uk/python/index.shtml

  #4  
Old July 18th, 2005, 10:56 PM
Ville Vainio
Guest
 
Posts: n/a
Default Re: Attaching to a Python Interpreter a la Tcl

>>>>> "fuzzyman" == Fuzzyman <fuzzyman@gmail.com> 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
  #5  
Old July 18th, 2005, 10:57 PM
Cameron Laird
Guest
 
Posts: n/a
Default Re: Attaching to a Python Interpreter a la Tcl

In article <421C6042.8060608@jessikat.fsnet.co.uk>,
Robin Becker <robin@SPAMREMOVEjessikat.fsnet.co.uk> wrote:[color=blue]
>DE wrote:[color=green]
>> 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,
>>[/color]
>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.[/color]
  #6  
Old July 18th, 2005, 10:57 PM
Stephen Thorne
Guest
 
Posts: n/a
Default Re: Attaching to a Python Interpreter a la Tcl

On 23 Feb 2005 02:37:48 -0800, DE <devrim.erdem@gmail.com> wrote:[color=blue]
> 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 ?[/color]

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
  #7  
Old July 18th, 2005, 10:58 PM
Jeff Epler
Guest
 
Posts: n/a
Default Re: Attaching to a Python Interpreter a la Tcl

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+F06x D5uZhrPgCeIwyz
HepI83ocgSrW+EoRD/BQ8Vc=
=vBV2
-----END PGP SIGNATURE-----

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles