本文整理汇总了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)
示例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)
示例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)
示例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()
示例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)
示例6: create_event_loop
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import SelectorEventLoop [as 别名]
def create_event_loop(self):
return asyncio.SelectorEventLoop()
示例7: setUp
# 需要导入模块: import asyncio [as 别名]
# 或者: from asyncio import SelectorEventLoop [as 别名]
def setUp(self):
self.loop = asyncio.SelectorEventLoop()
self.set_event_loop(self.loop)
示例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)
示例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)
示例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