portable way of sending notifying a process

Chris Angelico rosuav at gmail.com
Sun May 29 22:03:21 EDT 2011


On Mon, May 30, 2011 at 11:44 AM, Chris Torek <nospam at torek.net> wrote:
>>What would be a light weight portable way, that one process can tell
>>another to do something?
>>
>>The main requirement would be to have no CPU impact while waiting (thus
>>no polling)
>
> Your best bet here is probably to use sockets.  Both systems have
> ways to create service sockets and to connect to a socket as a
> client.

Further to this: If your two processes are going to start up, then run
concurrently for some time, and during that time alert each other (or
one alerts the other) frequently, a socket is an excellent choice. Use
a TCP socket on Windows, and either a TCP socket or a Unix socket on
Linux (I'd just use TCP on both for simplicity, but Unix sockets are
faster), and simply write a byte to it whenever you want to alert the
other side. You can largely guarantee that no other process can
accidentally or maliciously wake you, as long as you have some kind of
one-off handshake on connection - even something really simple like
sending a random nonce, having the other end send hash(nonce +
password), and compare.

Chris Angelico
Huge fan of TCP sockets (hello MUDs!)



More information about the Python-list mailing list