Sockets for a file
Alex Martelli
aleax at aleax.it
Wed Jul 24 07:29:21 EDT 2002
Teja Sastry wrote:
> Hi,
>
> I would like to know if we can create a unix socket for a file (like
> we do in C or C++ with struct sockaddr_un)
> I want to wait on a file in python and trigger some function if the
> file gets some data written in it by another program.
> Please clarify if anybody has worked on this previously.
I've done it, but not with sockets:
>>> import os
>>> os.mkfifo('/tmp/pappje')
>>> f=open('/tmp/pappje')
a wait here -- just as long as you want.
At some point in another terminal window:
echo ciao > /tmp/pappje
causes the Python interactive interpreter to wake up,
and prompt again -- whereupon you can, e.g.:
>>> print f.read()
ciao
>>> f.close()
>>>
Alex
More information about the Python-list
mailing list