Variables in a loop, Newby question

Cameron Simpson cs at zip.com.au
Thu Dec 26 02:01:26 CET 2013


On 25Dec2013 15:27, Denis McMahon <denismfmcmahon at gmail.com> wrote:
> On Wed, 25 Dec 2013 16:42:47 +1100, Cameron Simpson wrote:
> > On 25Dec2013 02:54, Denis McMahon <denismfmcmahon at gmail.com> wrote:
> >> On Tue, 24 Dec 2013 10:27:13 -0800, vanommen.robert wrote:
> >> > In this script i want to read the temperatures and make them
> >> > available to other scripts. [...]
> >> If you want this process to provide data to other processes, you might
> >> want to look at using a socket so they can request it as needed.
> > 
> > Or just write it to a file for another process to open and read...
> 
> That can cause io sync errors, eg if another process has the file opened 
> for read when you try to write, or you are writing when they try to read.

Well, obviously synchronisation of some kind is needed. The easiest
is write-new-file-with-temp-name followed by rename(). Atomic. Lock
files are also not too hard, etc.

> For inter process communication, sockets are generally better than files.

Except for agreement about the ports etc etc, and the need to write
a (possible trite) protocol. At least the filesystem gives great
and ergonomic flexibility about naming the communication point, and
offers file permissions to control who can access stuff instead of
needing some kind of authentication protocol. And of course a file
needs no connect/listen/accept daemon/thread to facilitate
communication.

Of course, a named pipe or UNIX cdomain socket may give the best of both
worlds, depending on the use case.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

In any event, this is a straw herring for debate.
        - solovay at netcom.com (Andrew Solovay)



More information about the Python-list mailing list