Bob Ippolito wrote:

> 
> On Oct 27, 2005, at 4:58 PM, Neal Becker wrote:
> 
>> Bob Ippolito wrote:
>>
>>
>>>
>>> On Oct 27, 2005, at 4:32 PM, Neal Becker wrote:
>>>
>>>
>>>> "Martin v. Löwis" wrote:
>>>>
>>>>
>>>>> I see. Python is making up the EISDIR, looking at the stat result.
>>>>> In Objects/fileobject.c:dircheck generates the EISDIR error, which
>>>>> apparently comes from posix_fdopen, PyFile_FromFile,
>>>>> fill_file_fields.
>>>>>
>>>>> Python simply does not support file objects which stat(2) as
>>>>> directories.
>>>>>
>>>>>
>>>>>
>>>>
>>>> OK, does python have a C API that would allow me to create a python
>>>> file
>>>> object from my C (C++) code?  Then instead of using python's fdopen
>>>> I could
>>>> just do it myself.
>>>>
>>>
>>> Why do you need a file object for something that is not a file
>>> anyway?  select.select doesn't require file objects for example, just
>>> objects that have a fileno() method.
>>>
>>>
>> Yes, that's a good point - the reason is I didn't want to restrict the
>> interface to only work with select.  Maybe I should rethink the
>> interface.
> 
> Well what would the interface do if you had a file object?  Are you
> supposed to be able to read/write/seek/tell/etc.?  I don't understand
> why you're trying to do what you're doing.  select.select was just an
> example, select.poll's register/unregister takes any object with a
> fileno also.
>

Yes, you are supposed to be able to read and get information.  However, I
have implemented fileno for it, so you can use select.select on it if you
just want to wait for something to happen - which is probably all that's
really needed.  I also implemented select as a method of my inotify object,
in case you prefer that.

Here's an excerpt from documentation/filesystems/inotify.txt:
-----------------
Events are provided in the form of an inotify_event structure that is
read(2)
from a given inotify instance.  The filename is of dynamic length and
follows
the struct. It is of size len.  The filename is padded with null bytes to
ensure proper alignment.  This padding is reflected in len.

You can slurp multiple events by passing a large buffer, for example

        size_t len = read (fd, buf, BUF_LEN);

Where "buf" is a pointer to an array of "inotify_event" structures at least
BUF_LEN bytes in size.  The above example will return as many events as are
available and fit in BUF_LEN.

Each inotify instance fd is also select()- and poll()-able.
-----------------

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to