Commit a8a76bc2 authored by Guido Trotter's avatar Guido Trotter

asycnotifier.AsyncNotifier

AsyncNotifier is a special asyncore class that delivers inotify events
asynchronously.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 01cf7dbe
......@@ -65,6 +65,7 @@ nodist_pkgpython_PYTHON = \
pkgpython_PYTHON = \
lib/__init__.py \
lib/asyncnotifier.py \
lib/backend.py \
lib/bdev.py \
lib/bootstrap.py \
......
#
#
# Copyright (C) 2009 Google Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
"""Asynchronous pyinotify implementation"""
import pyinotify
import asyncore
class AsyncNotifier(asyncore.file_dispatcher):
"""An asyncore dispatcher for inotify events.
"""
def __init__(self, watch_manager,
default_proc_fun=None,
map=None):
"""
Constructor for AsyncNotifier, a special asyncore file_dispatcher that
actually wraps a pyinotify Notifier, making it asyncronous.
"""
if default_proc_fun is None:
default_proc_fun=pyinotify.ProcessEvent()
self.notifier = pyinotify.Notifier(watch_manager, default_proc_fun)
# here we need to steal the file descriptor from the notifier, so we can
# use it in the global asyncore select, and avoid calling the
# check_events() function of the notifier (which doesn't allow us to select
# together with other file descriptors)
self.fd = self.notifier._fd
asyncore.file_dispatcher.__init__(self, self.fd, map)
def handle_read(self):
self.notifier.read_events()
self.notifier.process_events()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment