def defer_in_time(response, deltatime, callback_url): user_data, event = xxxx(response, callback_url, 0) timeval = libevent.timeval() timeval.tv_sec = int(deltatime) timeval.tv_usec = 0 # schedule! libevent.evtimer_set(user_data['byref(event)'], defer_in_time_hanlder_ptr, user_data['byref(id)'] ) libevent.evtimer_add(user_data['byref(event)'], ctypes.byref(timeval)) return response
def defer_for_fifo(response, file_name, deltatime, callback_url): fd = os.open(file_name, os.O_RDONLY | os.O_NONBLOCK) if not fd or fd < 0: print "open() ERROR" user_data, event = xxxx(response, callback_url, fd) timeval = libevent.timeval() timeval.tv_sec = int(deltatime) timeval.tv_usec = int((deltatime - int(deltatime))* 1000000) # schedule! libevent.event_set(user_data['byref(event)'], fd, libevent.EV_READ, defer_for_fifo_hanlder_ptr, user_data['byref(id)']) libevent.evtimer_add(user_data['byref(event)'], ctypes.byref(timeval)) response.schedule = user_data['byref(id)'] return response