當前位置: 首頁>>代碼示例>>Python>>正文


Python asyncio.SelectorEventLoop方法代碼示例

本文整理匯總了Python中asyncio.SelectorEventLoop方法的典型用法代碼示例。如果您正苦於以下問題:Python asyncio.SelectorEventLoop方法的具體用法?Python asyncio.SelectorEventLoop怎麽用?Python asyncio.SelectorEventLoop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在asyncio的用法示例。


在下文中一共展示了asyncio.SelectorEventLoop方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SelectorEventLoop [as 別名]
def __init__(self, task_pool, loop=None):
        """
        :param onedrived.od_task.TaskPool task_pool:
        :param asyncio.SelectorEventLoop | None loop:
        """
        self._lock = threading.RLock()
        self.watch_descriptors = loosebidict()
        self.task_queue = []
        self.task_pool = task_pool
        self.notifier = _INotify()
        if loop is None:
            import asyncio
            self.loop = asyncio.get_event_loop()
        else:
            self.loop = loop
        self.loop.add_reader(self.notifier.fd, self.process_events) 
開發者ID:xybu,項目名稱:onedrived-dev,代碼行數:18,代碼來源:od_watcher.py

示例2: setUp

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SelectorEventLoop [as 別名]
def setUp(self):
        if sys.platform == "win32":
            from asyncio.windows_events import ProactorEventLoop
            loop = ProactorEventLoop()
            asyncio.set_event_loop(loop)
        else:
            loop = asyncio.SelectorEventLoop()
            asyncio.set_event_loop(loop)

        self.loop = asyncio.get_event_loop()
        self.loop.set_debug(enabled=True)

        widgets = uistuff.GladeWidgets("PyChess.glade")
        gamewidget.setWidgets(widgets)
        perspective_manager.set_widgets(widgets)

        self.welcome_persp = Welcome()
        perspective_manager.add_perspective(self.welcome_persp)

        self.games_persp = Games()
        perspective_manager.add_perspective(self.games_persp) 
開發者ID:pychess,項目名稱:pychess,代碼行數:23,代碼來源:dialogs.py

示例3: __init__

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SelectorEventLoop [as 別名]
def __init__(
        self,
        sanitize_bracketed_paste: str = '[\x03\x04\x0e\x0f\r\x07\x7f\x8d\x8e\x8f\x90\x9b\x9d\x9e\x9f]'
    ):
        if is_macos:
            # On macOS PTY devices are not supported by the KqueueSelector and
            # the PollSelector is broken, causes 100% CPU usage
            self.asycio_loop: asyncio.AbstractEventLoop = asyncio.SelectorEventLoop(selectors.SelectSelector())
            asyncio.set_event_loop(self.asycio_loop)
        else:
            self.asycio_loop = asyncio.get_event_loop()
        self.return_code = 0
        self.read_buf = ''
        self.decoder = codecs.getincrementaldecoder('utf-8')('ignore')
        try:
            self.iov_limit = max(os.sysconf('SC_IOV_MAX') - 1, 255)
        except Exception:
            self.iov_limit = 255
        self.parse_input_from_terminal = partial(parse_input_from_terminal, self._on_text, self._on_dcs, self._on_csi, self._on_osc, self._on_pm, self._on_apc)
        self.ebs_pat = re.compile('([\177\r\x03\x04])')
        self.in_bracketed_paste = False
        self.sanitize_bracketed_paste = bool(sanitize_bracketed_paste)
        if self.sanitize_bracketed_paste:
            self.sanitize_ibp_pat = re.compile(sanitize_bracketed_paste) 
開發者ID:kovidgoyal,項目名稱:kitty,代碼行數:26,代碼來源:loop.py

示例4: main

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SelectorEventLoop [as 別名]
def main():
    """Main program.

    Parse arguments, set up event loop, run crawler, print report.
    """
    args = ARGS.parse_args()
    if not args.roots:
        print('Use --help for command line help')
        return

    log = Logger(args.level)

    if args.iocp:
        from asyncio.windows_events import ProactorEventLoop
        loop = ProactorEventLoop()
        asyncio.set_event_loop(loop)
    elif args.select:
        loop = asyncio.SelectorEventLoop()
        asyncio.set_event_loop(loop)
    else:
        loop = asyncio.get_event_loop()

    roots = {fix_url(root) for root in args.roots}

    crawler = Crawler(log,
                      roots, exclude=args.exclude,
                      strict=args.strict,
                      max_redirect=args.max_redirect,
                      max_tries=args.max_tries,
                      max_tasks=args.max_tasks,
                      max_pool=args.max_pool,
                      )
    try:
        loop.run_until_complete(crawler.crawl())  # Crawler gonna crawl.
    except KeyboardInterrupt:
        sys.stderr.flush()
        print('\nInterrupted\n')
    finally:
        crawler.report()
        crawler.close()
        loop.close() 
開發者ID:hhstore,項目名稱:annotated-py-projects,代碼行數:43,代碼來源:crawl.py

示例5: __init__

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SelectorEventLoop [as 別名]
def __init__(self):
        self._signal_safe_callbacks = []

        selector = _Selector(self)
        asyncio.SelectorEventLoop.__init__(self, selector) 
開發者ID:gmarull,項目名稱:asyncqt,代碼行數:7,代碼來源:_unix.py

示例6: create_event_loop

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SelectorEventLoop [as 別名]
def create_event_loop(self):
            return asyncio.SelectorEventLoop() 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:4,代碼來源:test_events.py

示例7: setUp

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SelectorEventLoop [as 別名]
def setUp(self):
        self.loop = asyncio.SelectorEventLoop()
        self.set_event_loop(self.loop) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:5,代碼來源:test_unix_events.py

示例8: set_read_ready

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SelectorEventLoop [as 別名]
def set_read_ready(fileobj, loop):
    """
    Schedule callbacks registered on ``loop`` as if the selector notified that
    data is ready to be read on ``fileobj``.

    :param fileobj: file object or :class:`~asynctest.FileMock` on which the
                    event is mocked.

    :param loop: :class:`asyncio.SelectorEventLoop` watching for events on
                 ``fileobj``.

    ::

        mock = asynctest.SocketMock()
        mock.recv.return_value = b"Data"

        def read_ready(sock):
            print("received:", sock.recv(1024))

        loop.add_reader(mock, read_ready, mock)

        set_read_ready(mock, loop)

        loop.run_forever() # prints received: b"Data"

    .. versionadded:: 0.4
    """
    # since the selector would notify of events at the beginning of the next
    # iteration, we let this iteration finish before actually scheduling the
    # reader (hence the call_soon)
    loop.call_soon_threadsafe(_set_event_ready, fileobj, loop, selectors.EVENT_READ) 
開發者ID:Martiusweb,項目名稱:asynctest,代碼行數:33,代碼來源:selector.py

示例9: set_write_ready

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SelectorEventLoop [as 別名]
def set_write_ready(fileobj, loop):
    """
    Schedule callbacks registered on ``loop`` as if the selector notified that
    data can be written to ``fileobj``.

    :param fileobj: file object or  :class:`~asynctest.FileMock` on which th
        event is mocked.
    :param loop: :class:`asyncio.SelectorEventLoop` watching for events on
        ``fileobj``.

    .. versionadded:: 0.4
    """
    loop.call_soon_threadsafe(_set_event_ready, fileobj, loop, selectors.EVENT_WRITE) 
開發者ID:Martiusweb,項目名稱:asynctest,代碼行數:15,代碼來源:selector.py

示例10: new_eventloop_with_inputhook

# 需要導入模塊: import asyncio [as 別名]
# 或者: from asyncio import SelectorEventLoop [as 別名]
def new_eventloop_with_inputhook(
    inputhook: Callable[["InputHookContext"], None]
) -> AbstractEventLoop:
    """
    Create a new event loop with the given inputhook.
    """
    selector = InputHookSelector(selectors.DefaultSelector(), inputhook)
    loop = asyncio.SelectorEventLoop(selector)
    return loop 
開發者ID:prompt-toolkit,項目名稱:python-prompt-toolkit,代碼行數:11,代碼來源:inputhook.py


注:本文中的asyncio.SelectorEventLoop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。