• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python select.kqueue函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testKqueue

 def testKqueue(self):
     k = select.kqueue()
     fd = FD(k)
     try:
         self.checkSubprocessFDs([fd], close=False)
     finally:
         del k
开发者ID:fmoo,项目名称:python-filedes,代码行数:7,代码来源:fd_remote.py


示例17: loop_kqueue

def loop_kqueue(timeout=0.0, map=None):
    if map is None:
        map = socket_map
    if timeout is not None:
        # timeout is in milliseconds
        timeout = int(timeout*1000)

    kq = select.kqueue()
    if map:
        evs = []
        for fd, obj in map.items():
            flags = select.KQ_EV_ADD | select.KQ_EV_CLEAR
            if obj.readable():
                evs.append(select.kevent(fd, filter=select.KQ_FILTER_READ, flags=flags))
            if obj.writable():
                evs.append(select.kevent(fd, filter=select.KQ_FILTER_WRITE, flags=flags))
        r_evs = kq.control(evs, 100, timeout)
        for ev in r_evs:
            obj = map.get(ev.ident)
            if obj is None:
                continue
            try:
                if ev.filter == select.KQ_FILTER_READ:
                    obj.handle_read_event()
                if ev.filter == select.KQ_FILTER_WRITE:
                    obj.handle_write_event()
            except socket.error, e:
                if e.args[0] not in (EBADF, ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED):
                    obj.handle_error()
                else:
                    obj.handle_close()
            except _reraised_exceptions:
                raise
            except:
开发者ID:davidrios,项目名称:mandel-exps,代码行数:34,代码来源:asynloop.py


示例18: worker_kill

    async def worker_kill(self, t_worker):
        # If connection has been closed lets make sure shell is killed
        if t_worker.shell_pid:

            try:
                kqueue = select.kqueue()
                kevent = select.kevent(t_worker.shell_pid, select.KQ_FILTER_PROC, select.KQ_EV_ADD | select.KQ_EV_ENABLE, select.KQ_NOTE_EXIT)
                kqueue.control([kevent], 0)

                os.kill(t_worker.shell_pid, signal.SIGTERM)

                # If process has not died in 2 seconds, try the big gun
                events = await self.middleware.run_in_thread(kqueue.control, None, 1, 2)
                if not events:
                    os.kill(t_worker.shell_pid, signal.SIGKILL)

                    # If process has not died even with the big gun
                    # There is nothing else we can do, leave it be and
                    # release the worker thread
                    events = await self.middleware.run_in_thread(kqueue.control, None, 1, 2)
                    if not events:
                        t_worker.die()
            except ProcessLookupError:
                pass

        # Wait thread join in yet another thread to avoid event loop blockage
        # There may be a simpler/better way to do this?
        await self.middleware.run_in_thread(t_worker.join)
开发者ID:rkojedzinszky,项目名称:freenas,代码行数:28,代码来源:main.py


示例19: start

    def start(self):
        try:
            self._kq = select.kqueue()
            kevents = []
            for f in self._files:
                self._files[f] = fd = os.open(f, os.O_RDONLY)

                ev = 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)
                kevents.append(ev)

            events = self._kq.control(kevents, 0)
            while True:
                events = self._kq.control(kevents, 1)
                fds = [e.ident for e in events]
                modified = [k for k, v in self._files.iteritems()
                                            if v in fds]
                self.on_change(modified)
        finally:
            self.close()
开发者ID:Ignas,项目名称:celery,代码行数:25,代码来源:autoreload.py


示例20: watch_files

def watch_files(filenames):
    def _watch_file(kq, filename, flags = select.KQ_EV_ADD | select.KQ_EV_ENABLE | select.KQ_EV_ONESHOT, fflags = select.KQ_NOTE_WRITE | select.KQ_NOTE_DELETE | select.KQ_NOTE_EXTEND | select.KQ_NOTE_RENAME):
        fd = os.open(filename, os.O_RDONLY)
        event = [select.kevent(fd, filter=select.KQ_FILTER_VNODE, flags=flags, fflags=fflags)]
        kq.control(event, 0, 0)
        return fd
    kq = select.kqueue()
    # filedescriptors -> filename
    fds = {}
    for filename in filenames:
        # expand out '~/' nonsense if its their
        filename = os.path.expanduser(filename)
        # get absolute path if its relative
        filename = os.path.abspath(filename)
        fds[_watch_file(kq, filename)] = filename
    try:
        events = kq.control([], 1, None)
    finally:
        kq.close()
        for fd in fds:
            os.close(fd)

    changed_files = set()
    for event in events:
        changed_files.add(fds[event.ident])

    return changed_files
开发者ID:spenthil,项目名称:waitchange,代码行数:27,代码来源:waitchange.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python select.poll函数代码示例发布时间:2022-05-27
下一篇:
Python select.error函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap