当前位置: 首页>>代码示例>>Python>>正文


Python select.kqueue函数代码示例

本文整理汇总了Python中select.kqueue函数的典型用法代码示例。如果您正苦于以下问题:Python kqueue函数的具体用法?Python kqueue怎么用?Python kqueue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了kqueue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_queue

 def test_create_queue(self):
     kq = select.kqueue()
     self.assertTrue(kq.fileno() > 0, kq.fileno())
     self.assertTrue(not kq.closed)
     kq.close()
     self.assertTrue(kq.closed)
     self.assertRaises(ValueError, kq.fileno)
开发者ID:2uller,项目名称:LotF,代码行数:7,代码来源:test_kqueue.py

示例2: _main

def _main():
    # Bootstrap by adding the root SId
    scope_add(ROOT_SID, ROOT_SID, ROOT_SID)
    
    # Open the events file and get its descriptor
    # (Note: This file is only read by scoped, not normal appications.)
    pubs_file = open("/pubsub/pubs")
    fd = pubs_file.fileno()
    
    # Register to events
    kq = select.kqueue()
    evf = select.kevent(fd,                     # ident
                        select.KQ_FILTER_VNODE, # filter
                        select.KQ_EV_ADD
                        | select.KQ_EV_CLEAR,   # flags
                        NOTE_PUBLISH,           # fflags
                        0,                      # data
                        0)                      # udata
    kq.control([evf], 0, None) # changelist, max_events, timeout
    
    # Listen to events
    while True:
        evl = kq.control(None, 1, None)
        
        if evl is not None:
            # Read events (SId/RId pairs)
            pub_evs = pep_get_sidrids(pubs_file)
            
            # Add scopes and/or publications
            for sid, rid in pub_evs:
                scope_add(ROOT_SID, sid, rid)
开发者ID:srcman,项目名称:blackhawk,代码行数:31,代码来源:scoped.py

示例3: start_monitor

def start_monitor(dirs):
    last_run = time.time()
    files_stats = []
    paths = []
    current_dir = os.getcwd()

    kq = kqueue()

    source_events = []
    for dir_name in dirs:
        dir_path = current_dir + '/' + dir_name
        paths.append(dir_path)
        fd = os.open(dir_path, os.O_RDONLY)
        event = kevent(fd, filter=select.KQ_FILTER_VNODE,
                        flags=select.KQ_EV_ADD | select.KQ_EV_CLEAR,
                        fflags=select.KQ_NOTE_WRITE)
        source_events.append(event)

    while True:
        events = kq.control(source_events,  len(source_events), 2000)
        if any(map(lambda e: e.fflags & select.KQ_NOTE_WRITE, events)):
            if (time.time() - last_run) < LIMIT:
                continue
            if check_modifications(current_dir, paths):
                try:
                    async_test(["make", "test"])
                    os.system('clear')
                    subprocess.Popen("neurotic")
                except NeuroticError as ne:
                    os.system('clear')
                    if b"ERROR" in ne.content[0]:
                        print(ne.content[0])
                    else:
                        subprocess.Popen("neurotic")
                last_run = time.time()
开发者ID:loogica,项目名称:neurotic,代码行数:35,代码来源:osx_file_monitor.py

示例4: worker

    def worker(self):
        self.logger.debug("Opened tail stream on file {0} ({1} lines)".format(self.path, self.backlog))
        with io.open(self.fd, "wb") as fd:
            with open(self.path, "rb") as f:
                kq = select.kqueue()
                try:
                    ev = [
                        select.kevent(
                            fd.fileno(), filter=select.KQ_FILTER_READ, flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE
                        ),
                        select.kevent(
                            f.fileno(), filter=select.KQ_FILTER_READ, flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE
                        ),
                    ]

                    fd.write(self.tail(f, self.backlog))
                    fd.flush()

                    kq.control(ev, 0)
                    f.seek(0, os.SEEK_END)

                    while True:
                        event, = kq.control(None, 1)
                        self.logger.debug("kqueue event {0}".format(event))
                        if event.ident == fd.fileno():
                            if event.flags & select.KQ_EV_EOF or event.flags & select.KQ_EV_ERROR:
                                break

                        if event.ident == f.fileno():
                            fd.write(f.read())
                            fd.flush()
                finally:
                    kq.close()
开发者ID:freenas,项目名称:middleware,代码行数:33,代码来源:main.py

示例5: run

    def run(self, *args, **kwargs):
        super(pbid, self).run(*args, **kwargs)

        """
        pbid --refresh is async and will remove /var/db/pbi/index/*.time,
        once the refresh is done the file will exist again.
        Wait for the file using kqueue for the sync operation
        """
        if self.__sync is True and self.flags & PBID_FLAGS_REFRESH:
            fd = os.open(PBID_INDEXDIR, os.O_RDONLY)
            evts = [
                select.kevent(fd,
                    filter=select.KQ_FILTER_VNODE,
                    flags=select.KQ_EV_ADD | select.KQ_EV_CLEAR,
                    fflags=select.KQ_NOTE_WRITE | select.KQ_NOTE_EXTEND,
                )
            ]
            kq = select.kqueue()
            kq.control(evts, 0, 0)
            timeout = True
            for i in xrange(30):
                kq.control(None, 2, 1)
                if len(glob.glob('%s/*.time' % PBID_INDEXDIR)) > 0:
                    timeout = False
                    break

            if timeout:
                log.debug("pbid.run: sync refresh timed out")
开发者ID:Blackwarg,项目名称:freenas,代码行数:28,代码来源:pbi.py

示例6: __init__

 def __init__(self):
     self._fd_map = {}
     self._handler_map = {}
     self._event_map = {}
     self.kq = select.kqueue()
     self.klist = []
     self._stop = False
开发者ID:xh4n3,项目名称:decode_ss,代码行数:7,代码来源:nonblock.py

示例7: __init__

    def __init__(self, AutoBot, listenhost, listenport):
        Thread.__init__(self)
        self.setDaemon(1)
        self.AutoBot = AutoBot
        self.listenport = listenport

        self.accept_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.accept_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        #self.accept_socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
        self.accept_socket.bind((listenhost, listenport))
        self.accept_socket.listen(10)
        self.accept_socket.setblocking(False)
        #self.accept_socket.settimeout(None)

        #for bsd
        self.kq = select.kqueue()
        self.kevent = [
                   select.kevent(self.accept_socket.fileno(),
                   filter=select.KQ_FILTER_READ,
                   flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE)
        ]

        #for linux
        #self.epoll = select.epoll()
        #self.epoll.register(self.accept_socket.fileno(), select.EPOLLIN)

        self.stuff = {}
开发者ID:meskarune,项目名称:autobot,代码行数:27,代码来源:botold.py

示例8: do_work_kqueue

def do_work_kqueue(start, end, port, get_hostname):
    print "kqueue scanning "+int2ip(start)+" to "+int2ip(end)
    connected = []
    total = end-start

    while (start <= end):
        kq = select.kqueue()
        fd_map = {}
        kevents = []
        while (start <= end):
            try:
                s = open_adb_socket(int2ip(start),port)
            except:
                break
            else:
                fd_map[s.fileno()] = (start,s)
                start = start+1
                kevents.append(select.kevent(s,filter=select.KQ_FILTER_WRITE))
        kq.control(kevents,0,0)
        time.sleep(0.2)
        for k in kq.control([],len(kevents),0.1):
            w = fd_map[k.ident][1]
            addr = fd_map[w.fileno()][0]
            if w.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR) == 0:
                print 'ADDCON2', k.ident, w.fileno(), int2ip(addr), fd_map[w.fileno()]
                connected.append(int2ip(addr))
        for fd,t in fd_map.iteritems():
            t[1].close()
        sys.stdout.write("\r%d/%d" % (total-(end-start),total))
        sys.stdout.flush()
    print
    if get_hostname:
        for c in connected:
            connect_with_adb(c,port)
开发者ID:acw1251,项目名称:connectal,代码行数:34,代码来源:discover_tcp.py

示例9: watch_parent

def watch_parent():
    """
    Thread to watch for the parent pid.
    If this process has been orphaned it means middlewared process has crashed
    and there is nothing left to do here other than commit suicide!
    """
    kqueue = select.kqueue()

    try:
        kqueue.control([
            select.kevent(
                os.getppid(),
                filter=select.KQ_FILTER_PROC,
                flags=select.KQ_EV_ADD,
                fflags=select.KQ_NOTE_EXIT,
            )
        ], 0, 0)
    except ProcessLookupError:
        os._exit(1)

    while True:
        ppid = os.getppid()
        if ppid == 1:
            break
        kqueue.control(None, 1)

    os._exit(1)
开发者ID:freenas,项目名称:freenas,代码行数:27,代码来源:worker.py

示例10: connect

    def connect(self, connectionInfo, elementListener):
        """
        Connect according to the info in connectionInfo, and use
        elementListener.

        :param UdpTransport.ConnectionInfo connectionInfo: A
          UdpTransport.ConnectionInfo.
        :param elementListener: The elementListener must remain valid during the
          life of this object.
        :type elementListener: An object with onReceivedData
        """
        self.close()
        # Save the _address to use in sendto.
        self._address = (connectionInfo.getHost(), connectionInfo.getPort())
        self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

        if hasattr(select, "poll"):
            # Set up _poll.  (Ubuntu, etc.)
            self._poll = select.poll()
            self._poll.register(self._socket.fileno(), select.POLLIN)
        elif hasattr(select, "kqueue"):
            ## Set up _kqueue. (BSD and OS X)
            self._kqueue = select.kqueue()
            self._kevents = [select.kevent(
              self._socket.fileno(), filter = select.KQ_FILTER_READ,
              flags = select.KQ_EV_ADD | select.KQ_EV_ENABLE |
                      select.KQ_EV_CLEAR)]
        elif not hasattr(select, "select"):
            # Most Python implementations have this fallback, so we
            #   don't expect this error.
            raise RuntimeError("Cannot find a polling utility for sockets")

        self._elementReader = ElementReader(elementListener)
开发者ID:cawka,项目名称:PyNDN2,代码行数:33,代码来源:udp_transport.py

示例11: __watch

    def __watch(self):
        kq = select.kqueue()
        passwd_fd = os.open(self.passwd_filename, os.O_RDONLY)
        group_fd = os.open(self.group_filename, os.O_RDONLY)

        ev = [
            select.kevent(
                passwd_fd,
                filter=select.KQ_FILTER_VNODE, flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE,
                fflags=select.KQ_NOTE_WRITE | select.KQ_NOTE_EXTEND | select.KQ_NOTE_RENAME
            ),
            select.kevent(
                group_fd,
                filter=select.KQ_FILTER_VNODE, flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE,
                fflags=select.KQ_NOTE_WRITE | select.KQ_NOTE_EXTEND | select.KQ_NOTE_RENAME
            )
        ]

        kq.control(ev, 0)

        while True:
            event, = kq.control(None, 1)
            name = self.passwd_filename if event.ident == passwd_fd else self.group_filename
            logger.warning('{0} was modified, reloading'.format(name))
            self.__load()
开发者ID:erinix,项目名称:middleware,代码行数:25,代码来源:FlatFilePlugin.py

示例12: wait_for_file_change

    def wait_for_file_change(self, path, timeout=0):
        changed = False

        with open(path, "r") as f:
            fd = f.fileno()
            kq = select.kqueue()

            events = [select.kevent(
                fd, filter=select.KQ_FILTER_VNODE,
                flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE | select.KQ_EV_CLEAR,
                fflags=select.KQ_NOTE_WRITE | select.KQ_NOTE_EXTEND
            )]

            events = kq.control(events, 0, 0)
            while (not changed):
                proc_events = kq.control([], 1024)
                for event in proc_events:
                    if ((event.fflags & select.KQ_NOTE_WRITE) or
                            (event.fflags & select.KQ_NOTE_EXTEND)):
                            if os.access(path, os.F_OK):
                                changed = True

                if changed is True:
                    break

            kq.close()

        return changed
开发者ID:razzfazz,项目名称:freenas,代码行数:28,代码来源:mdns.py

示例13: wait_for_file_to_exist

    def wait_for_file_to_exist(self, path, timeout=0):
        path_dir = os.path.abspath(os.path.realpath(os.path.dirname(path)))
        filename = os.path.basename(path)
        fullpath = os.path.join(path_dir, filename)
        exists = False

        fd = os.open(path_dir, os.O_RDONLY)
        kq = select.kqueue()

        events = [select.kevent(
            fd, filter=select.KQ_FILTER_VNODE,
            flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE | select.KQ_EV_CLEAR,
            fflags=select.KQ_NOTE_WRITE | select.KQ_NOTE_EXTEND
        )]

        events = kq.control(events, 0, 0)
        while (not exists):
            proc_events = kq.control([], 1024)
            for event in proc_events:
                if ((event.fflags & select.KQ_NOTE_WRITE) or
                        (event.fflags & select.KQ_NOTE_EXTEND)):
                        if os.access(fullpath, os.F_OK):
                            exists = True

            if exists is True:
                break

        kq.close()
        os.close(fd)

        return exists
开发者ID:razzfazz,项目名称:freenas,代码行数:31,代码来源:mdns.py

示例14: __init__

 def __init__(self):
     Base.__init__(self)
     Base._poller = self
     if hasattr(select, 'epoll'):
         self._epoll = select.epoll()
     elif hasattr(select, 'kqueue'):
         self._kqueue = select.kqueue()
开发者ID:ThomasCr,项目名称:smarthome,代码行数:7,代码来源:connection.py

示例15: kqueue_poller

def kqueue_poller(timeout=0.0, map=None):
    """A poller which uses kqueue(), BSD specific."""
    if map is None:
        map = socket_map
    if map:
        kqueue = select.kqueue()
        flags = select.KQ_EV_ADD | select.KQ_EV_ENABLE
        selectables = 0
        for fd, obj in map.items():
            filter = 0
            if obj.readable():
                filter |= select.KQ_FILTER_READ
            if obj.writable():
                filter |= select.KQ_FILTER_WRITE
            if filter:
                ev = select.kevent(fd, filter=filter, flags=flags)
                kqueue.control([ev], 0)
                selectables += 1

        events = kqueue.control(None, selectables, timeout)
        for event in events:
            fd = event.ident
            obj = map.get(fd)            
            if obj is None:
                continue
            if event.filter == select.KQ_FILTER_READ:
                read(obj)
            if event.filter == select.KQ_FILTER_WRITE:
                write(obj)
        kqueue.close()
开发者ID:linluxiang,项目名称:greenio,代码行数:30,代码来源:asyncore_epoll.py


注:本文中的select.kqueue函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。