dsoprea / PyInotify

An efficient and elegant inotify (Linux filesystem activity monitor) library for Python. Python 2 and 3 compatible.
GNU General Public License v2.0
242 stars 73 forks source link

how is filter_predicate intended to be used? #72

Closed erpadmin closed 5 years ago

erpadmin commented 5 years ago

Inotify class function event_gen excerpt:

                    for type_name in type_names:
                        if filter_predicate is not None and \
                           filter_predicate(type_name, e) is False:
self.__last_success_return = (type_name, e)

its expecting it to be callable?

dsoprea commented 5 years ago

Yes. It shows that, no?

You get the type-name and event-info, and need to return a boolean (hence, a predicate).

dwvisser commented 5 years ago

I think that, at the very least, the fact that the filter_predicate is used to shortcut all event processing should be documented in a detailed docstring for event_gen(). Something like what I had to search out in release notes:

Can now provide filter_predicate to event_gen() to allow custom loop termination based on events.

I was burned by this yesterday, because I naively assumed that filter_predicate was a way to select which events I wanted to handle, like the Python built-in filter(). It was also necessary to go digging deep in the event_gen() code to find the expected signature of the predicate, not ideal for someone who just wants to use this as a library.