Communication between python scripts

C

Chris

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.
 
C

Chris Grebeldinger

There are many ways, for instance you could use SimpleXMLRPCServer and
have one app expose a done_process() function, and use that to
synchronize.
 
P

Peter Hansen

Chris said:
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".
 
?

=?ISO-8859-15?Q?Andr=E9_S=F8reng?=

Chris said:
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/module-SimpleXMLRPCServer.html

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

Other that that, you could also just use regular sockets.
 
H

Heiko Wundram

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)

iD8DBQBCJNvwf0bpgh6uVAMRAqRBAJ0XqMfFZYjGhiQqUqBZIVcQsLLs0wCZAc/j
dVjIDof2EAtl/YfyTdT1un4=
=nIgp
-----END PGP SIGNATURE-----
 
D

Do Re Mi chel La Si Do

Hi !

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

@-salutations
 
D

Do Re Mi chel La Si Do

Hi !

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

@-salutations
 
P

Peter Hansen

Do said:
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
 
S

Stephen Toledo-Brown

Heiko said:
Am Dienstag, 1. März 2005 21:54 schrieb Chris:
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top