Communication between python scripts

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chris

    #1

    Communication between python scripts

    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 Grebeldinger

    #2
    Re: Communication between python scripts

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

    Comment

    • Peter Hansen

      #3
      Re: Communication between python scripts

      Chris wrote:[color=blue]
      > 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.[/color]

      Google for "python remote objects" and click on "I'm Feeling Lucky".

      Comment

      • André Søreng

        #4
        Re: Communication between python scripts

        Chris wrote:[color=blue]
        > 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.
        >[/color]

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

        client access:


        server:


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

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

        Comment

        • Heiko Wundram

          #5
          Re: Communication between python scripts

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

          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 SimpleXMLRPCSer ver),

          4) write both programs so that they spawn an additional thread which runs a
          socket server (e.g. SimpleXMLRPCSer ver) 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)

          iD8DBQBCJNvwf0b pgh6uVAMRAqRBAJ 0XqMfFZYjGhiQqU qBZIVcQsLLs0wCZ Ac/j
          dVjIDof2EAtl/YfyTdT1un4=
          =nIgp
          -----END PGP SIGNATURE-----

          Comment

          • Do Re Mi chel La Si Do

            #6
            Re: Communication between python scripts

            Hi !

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

            @-salutations
            --
            Michel Claveau


            Comment

            • Do Re Mi chel La Si Do

              #7
              Re: Communication between python scripts


              Hi !

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

              @-salutations
              --
              Michel Claveau



              Comment

              • Peter Hansen

                #8
                Re: Communication between python scripts

                Do Re Mi chel La Si Do wrote:[color=blue]
                > A socket (TCP) server is more simplist than XML-RPC, and 30 x faster.[/color]

                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

                Comment

                • Stephen Toledo-Brown

                  #9
                  Re: Communication between python scripts

                  Heiko Wundram wrote:
                  [color=blue]
                  > Am Dienstag, 1. März 2005 21:54 schrieb Chris:
                  >[color=green]
                  >>Is there a preferred method for having different scripts on different
                  >>computers communicate with each other?[/color][/color]
                  <snip>[color=blue]
                  > You have several options at your disposal.[/color]
                  [color=blue]
                  > 6) do something else which doesn't come to my mind just now. ;)[/color]

                  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

                  Comment

                  • gaudetteje@gmail.com

                    #10
                    Re: Communication between python scripts

                    Another reason NOT to use XML-RPC:

                    PSF-2005-001 - SimpleXMLRPCSer ver.py allows unrestricted traversal


                    Comment

                    Working...