def create_watcher_callback(watcher):
    """
    Create custom callback functions for each watcher
    """
    # get reference to the class so we can use it to look up this
    # specific watcher without using a reference to the watcher
    watcher_class = watcher.__class__
    
    def watcher_callback(loop_struct_pointer, watcher_struct_pointer, revents):
        w = watcher_class.lookup_instance(watcher_struct_pointer.contents)
        gevent_callback(w, revents)

    return libev.wrap_callback(watcher.type, watcher_callback)
    global HANDLING_SIGINT
    HANDLING_SIGINT = True

signal.signal(signal.SIGINT, _handle_sigint)

def _gevent_signal_check(loop_struct_pointer, watcher_struct_pointer, revents):
    loop = Loop.lookup_instance(loop_struct_pointer)
    global HANDLING_SIGINT
    if HANDLING_SIGINT:
        HANDLING_SIGINT = False
        try:
            raise KeyboardInterrupt()
        except KeyboardInterrupt:
            exc_info = sys.exc_info()
        loop.handle_error(loop, *exc_info)
gevent_signal_check = libev.wrap_callback("prepare", _gevent_signal_check)

def gevent_periodic_signal_check(loop, watcher, revents):
    raise Exception("unimplemented")

def create_watcher_callback(watcher):
    """
    Create custom callback functions for each watcher
    """
    # get reference to the class so we can use it to look up this
    # specific watcher without using a reference to the watcher
    watcher_class = watcher.__class__
    
    def watcher_callback(loop_struct_pointer, watcher_struct_pointer, revents):
        w = watcher_class.lookup_instance(watcher_struct_pointer.contents)
        gevent_callback(w, revents)