Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Allow functions as event handlers #1043

Open
za3k opened this issue Jul 3, 2024 · 0 comments
Open

Feature Request: Allow functions as event handlers #1043

za3k opened this issue Jul 3, 2024 · 0 comments

Comments

@za3k
Copy link

za3k commented Jul 3, 2024

To make user code potentially lighter-weight, I'd like to pass a function as an event handler.

Here's some equivalent code:

class FunctionEventHandler(watchdog.events.FileSystemEventHandler):
    def __init__(self, f):
        self.f = f
    def on_any_event(self, event):
        self.f(event)

Example usage:

observer.schedule(
    FunctionEventHandler(updates.put),
    path,
    recursive=True
)

where updates.put is here the function (updates is a python queue.Queue)

My feature request is to add this into the library, so I can instead call:

observer.schedule(updates.put, path, recursive=True)

and leave out the definition of FunctionEventHandler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant