Communication between python scripts

Discussion in 'Python' started by Chris, Mar 1, 2005.

  1. Chris

    Chris Guest

    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.
     
    Chris, Mar 1, 2005
    #1
    1. Advertising

  2. There are many ways, for instance you could use SimpleXMLRPCServer and
    have one app expose a done_process() function, and use that to
    synchronize.
     
    Chris Grebeldinger, Mar 1, 2005
    #2
    1. Advertising

  3. Chris

    Peter Hansen Guest

    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".
     
    Peter Hansen, Mar 1, 2005
    #3
  4. 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/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.
     
    =?ISO-8859-15?Q?Andr=E9_S=F8reng?=, Mar 1, 2005
    #4
  5. 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-----
     
    Heiko Wundram, Mar 1, 2005
    #5
  6. Hi !

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

    @-salutations
    --
    Michel Claveau
     
    Do Re Mi chel La Si Do, Mar 1, 2005
    #6
  7. Hi !

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

    @-salutations
    --
    Michel Claveau
     
    Do Re Mi chel La Si Do, Mar 1, 2005
    #7
  8. Chris

    Peter Hansen Guest

    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
     
    Peter Hansen, Mar 2, 2005
    #8
  9. 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
     
    Stephen Toledo-Brown, Mar 4, 2005
    #9
  10. Chris

    Guest

    , Mar 4, 2005
    #10
    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. ChrisH
    Replies:
    5
    Views:
    358
    Irmen de Jong
    Sep 14, 2004
  2. Tim Golden
    Replies:
    1
    Views:
    417
    Cameron Laird
    Sep 14, 2004
  3. Jan Danielsson
    Replies:
    8
    Views:
    629
    Mike Meyer
    Jul 22, 2005
  4. Jp Calderone
    Replies:
    0
    Views:
    459
    Jp Calderone
    Jul 21, 2005
  5. davidj411
    Replies:
    0
    Views:
    512
    davidj411
    Jun 27, 2008
Loading...

Share This Page