Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Communication between python scripts

Reply
Thread Tools

Communication between python scripts

 
 
Chris
Guest
Posts: n/a
 
      03-01-2005
Is there a preferred method for having different scripts on different
computers communicate with each other?

For example, script A could tell script B that it is done with a certain
process.

I know how to do this using e-mail, but I would like a more direct
method if possible. If my ISP's mail server goes down, for example, I
don't want my processes to come to a screeching halt.

 
Reply With Quote
 
 
 
 
Chris Grebeldinger
Guest
Posts: n/a
 
      03-01-2005
There are many ways, for instance you could use SimpleXMLRPCServer and
have one app expose a done_process() function, and use that to
synchronize.

 
Reply With Quote
 
 
 
 
Peter Hansen
Guest
Posts: n/a
 
      03-01-2005
Chris wrote:
> Is there a preferred method for having different scripts on different
> computers communicate with each other?
>
> For example, script A could tell script B that it is done with a certain
> process.
>
> I know how to do this using e-mail, but I would like a more direct
> method if possible. If my ISP's mail server goes down, for example, I
> don't want my processes to come to a screeching halt.


Google for "python remote objects" and click on "I'm Feeling Lucky".
 
Reply With Quote
 
=?ISO-8859-15?Q?Andr=E9_S=F8reng?=
Guest
Posts: n/a
 
      03-01-2005
Chris wrote:
> Is there a preferred method for having different scripts on different
> computers communicate with each other?
>
> For example, script A could tell script B that it is done with a certain
> process.
>
> I know how to do this using e-mail, but I would like a more direct
> method if possible. If my ISP's mail server goes down, for example, I
> don't want my processes to come to a screeching halt.
>


Probably the simplest way would be to use XMLRPC. Python
supports it both on client and server side.

client access:
http://www.python.org/doc/2.4/lib/module-xmlrpclib.html

server:
http://www.python.org/doc/2.4/lib/mo...RPCServer.html

Examples to get you going are also available in the library reference.

Other that that, you could also just use regular sockets.
 
Reply With Quote
 
Heiko Wundram
Guest
Posts: n/a
 
      03-01-2005
Am Dienstag, 1. März 2005 21:54 schrieb Chris:
> Is there a preferred method for having different scripts on different
> computers communicate with each other?


You have several options at your disposal.

1) Use mail-communication (like you said, a combination of smtplib and
poplib/imaplib),

2) have the scripts update web-pages which can be accessed by the other script
to read status information (a combination of ftplib and urllib2),

3) write a socket server process running on some computer which can be
connected by both clients to update certain flags which can then be read by
the other process (see SimpleXMLRPCServer),

4) write both programs so that they spawn an additional thread which runs a
socket server (e.g. SimpleXMLRPCServer) which can be used to query their
state from the other process,

5) use some RPC-package like Pyro (http://pyro.sourceforge.net/),
Twisted+Banana (http://www.twistedmatrix.com/), CORBA, etc.

6) do something else which doesn't come to my mind just now.

You have many options at your disposal, and which of the above options you
choose will depend largely on what your prerequesites are, such as:

1) Do both machines reside on the same network, or do they need gateways to
communicate (like a mail server in option 1)?

2) Are you willing to install packages like Pyro which do not belong to the
stdlib on both computers?

3) Can you run some server process on a machine which is reachable by both
processes?

4) And anything else which I didn't think of just now...

I'd say, if you aren't constrained in some form, go for Pyro to start with.
Nice and simple.

--
--- Heiko.

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

iD8DBQBCJNvwf0bpgh6uVAMRAqRBAJ0XqMfFZYjGhiQqUqBZIV cQsLLs0wCZAc/j
dVjIDof2EAtl/YfyTdT1un4=
=nIgp
-----END PGP SIGNATURE-----

 
Reply With Quote
 
Do Re Mi chel La Si Do
Guest
Posts: n/a
 
      03-01-2005
Hi !

A socket (TCP) server is very easy, and 30 x faster than XML-RPC.

@-salutations
--
Michel Claveau


 
Reply With Quote
 
Do Re Mi chel La Si Do
Guest
Posts: n/a
 
      03-01-2005

Hi !

A socket (TCP) server is more simplist than XML-RPC, and 30 x faster.

@-salutations
--
Michel Claveau



 
Reply With Quote
 
Peter Hansen
Guest
Posts: n/a
 
      03-02-2005
Do Re Mi chel La Si Do wrote:
> A socket (TCP) server is more simplist than XML-RPC, and 30 x faster.


Is it "more simplist" in terms of reliability? Generally
most people writing low-level socket code, even in Python,
do an absymal job of it. Far better to avoid reinventing
the wheel and use something higher level where the odds
are good that most of the nitty-gritty details have been
handled and tested already.

And as for "30x faster", please repeat after me: "premature
optimization is the root of all evil in programming".

-Peter
 
Reply With Quote
 
Stephen Toledo-Brown
Guest
Posts: n/a
 
      03-04-2005
Heiko Wundram wrote:

> Am Dienstag, 1. März 2005 21:54 schrieb Chris:
>
>>Is there a preferred method for having different scripts on different
>>computers communicate with each other?

<snip>
> You have several options at your disposal.


> 6) do something else which doesn't come to my mind just now.


The main one missing seems to be using asynchronous middleware - either
database or Messsage Queuing. e.g. there's pymqi for a Python interface
to WebSphereMQ, or there are some lighter-weight open-source
alternatives if you don't need that level of robustness.

Note that between all these alternatives, there are 2 fundamentally
different categories: synchronous (sockets, RPC) or asynchronous (email,
ftp, MQ, etc). Getting that first decision right is much more important
than choosing between the methods within each category because
synchronous vs. asynchronous affects your basic app design, whereas
refactoring between different synchronous methods or between
asynchronous methods, is relatively easy.
--
Steve Toledo-Brown
Speaking for myself only.
Domain: uk.ibm.com
 
Reply With Quote
 
gaudetteje@gmail.com
Guest
Posts: n/a
 
      03-04-2005
Another reason NOT to use XML-RPC:

PSF-2005-001 - SimpleXMLRPCServer.py allows unrestricted traversal
http://python.org/security/PSF-2005-001/

 
Reply With Quote
 
 
 
Reply

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Python Scripts with IIS - ASP or Python-based CGI scripts withIIS - which makes more sense? davidj411 Python 0 06-27-2008 04:38 PM
Stupid question: Making scripts python-scripts Jan Danielsson Python 8 07-22-2005 12:20 AM
Re: Stupid question: Making scripts python-scripts Jp Calderone Python 0 07-21-2005 02:38 PM
RE: Communication between remote scripts Tim Golden Python 1 09-14-2004 09:08 PM
Communication between remote scripts ChrisH Python 5 09-14-2004 07:25 PM



Advertisments