예제 #1
0
def _on_tick_(timer):
    ec = core.get_ec()
    self = ec.handles.get(timer, Timer)
    try:
        Event_dispatch(self.on_tick, [])
    except Unwinder as unwinder:
        core.root_unwind(ec, unwinder)
예제 #2
0
파일: uv_handle.py 프로젝트: gordol/lever
def _on_close_(handle):
    ec = core.get_ec()
    self = ec.handles.free(handle)
    self.closed = True
    try:
        Event_dispatch(self.on_close, [])
        for event in self.events:
            Event_close(event)
    except Unwinder as unwinder:
        core.root_unwind(unwinder)
예제 #3
0
파일: __init__.py 프로젝트: gordol/lever
def invoke_callback(ffi_cif, ll_res, ll_args, ll_userdata):
    """ Callback specification.
    ffi_cif - something ffi specific, don't care
    ll_args - rffi.VOIDPP - pointer to array of pointers to args
    ll_res - rffi.VOIDP - pointer to result
    ll_userdata - a special structure which holds necessary information
                  (what the real callback is for example), casted to VOIDP
    """
    # Reveal the callback.
    addr = rffi.cast(llmemory.Address, ll_userdata)
    gcref = rgc.reveal_gcref(addr)
    callback = rgc.try_cast_gcref_to_instance(Callback, gcref)
    if callback is None:
        try:
            os.write(STDERR,
                "Critical error: invoking a callback that was already freed\n")
        except:
            pass
        # We cannot do anything here.
    else:
        #must_leave = False
        try:
            # must_leave = space.threadlocals.try_enter_thread(space)
            # Should check for separate threads here and crash
            # if the callback comes from a thread that has no execution context.
            cfunc = callback.cfunc
            argv = []
            for i in range(0, len(cfunc.argtypes)):
                argv.append( cfunc.argtypes[i].load(ll_args[i], False) )
            value = callback.callback.call(argv)
            if isinstance(cfunc.restype, Type):
                cfunc.restype.store(None, ll_res, value)
        except Unwinder as unwinder:
            core.root_unwind(unwinder)
        except Exception as e:
            try:
                os.write(STDERR, "SystemError: callback raised ")
                os.write(STDERR, str(e))
                os.write(STDERR, "\n")
            except:
                pass
예제 #4
0
def _fs_event_cb_(handle, filename, events, status):
    ec = core.get_ec()
    try:
        self = uv_callback.peek(ec.uv__fs_event, handle)
        status = rffi.r_long(status)
        if self.status == 0 and status < 0:
            uv_callback.drop(ec.uv__fs_event, handle)
            self.status = status
            return
        obj = Exnihilo()
        obj.setattr(u"path", from_cstring(rffi.charp2str(filename)))
        if rffi.r_long(events) == 1:
            obj.setattr(u"type", String(u"rename"))
        else:
            obj.setattr(u"type", String(u"change"))
        if self.greenlet is None:
            self.data.append(obj)
        else:
            greenlet, self.greenlet = self.greenlet, None
            core.switch([greenlet, obj])
    except Unwinder as unwinder:
        core.root_unwind(ec, unwinder)