本文整理匯總了Python中asyncio.events.AbstractEventLoop方法的典型用法代碼示例。如果您正苦於以下問題:Python events.AbstractEventLoop方法的具體用法?Python events.AbstractEventLoop怎麽用?Python events.AbstractEventLoop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類asyncio.events
的用法示例。
在下文中一共展示了events.AbstractEventLoop方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def __init__(self, loop: AbstractEventLoop = None, **kwargs):
super(BleakScannerBlueZDBus, self).__init__(loop, **kwargs)
self._device = kwargs.get("device", "hci0")
self._reactor = None
self._bus = None
self._cached_devices = {}
self._devices = {}
self._rules = list()
# Discovery filters
self._filters = kwargs.get("filters", {})
self._filters["Transport"] = "le"
self._adapter_path = None
self._interface = None
self._callback = None
示例2: __init__
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def __init__(self, loop: AbstractEventLoop = None, **kwargs):
super(BleakScannerDotNet, self).__init__(loop, **kwargs)
self.watcher = None
self._devices = {}
self._scan_responses = {}
self._callback = None
if "scanning_mode" in kwargs and kwargs["scanning_mode"].lower() == "passive":
self._scanning_mode = BluetoothLEScanningMode.Passive
else:
self._scanning_mode = BluetoothLEScanningMode.Active
self._signal_strength_filter = kwargs.get("SignalStrengthFilter", None)
self._advertisement_filter = kwargs.get("AdvertisementFilter", None)
示例3: __init__
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def __init__(
self,
callback: Callable,
period: float,
start_at: Optional[datetime.datetime] = None,
exception_callback: Optional[Callable[[Callable, Exception], None]] = None,
loop: Optional[AbstractEventLoop] = None,
):
"""
Init periodic caller.
:param callback: function to call periodically
:param period: period in seconds.
:param start_at: optional first call datetime
:param exception_callback: optional handler to call on exception raised.
:param loop: optional asyncio event loop
"""
self._loop = loop or asyncio.get_event_loop()
self._periodic_callable = callback
self._start_at = start_at or datetime.datetime.now()
self._period = period
self._timerhandle: Optional[TimerHandle] = None
self._exception_callback = exception_callback
示例4: ensure_loop
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def ensure_loop(loop: AbstractEventLoop = None) -> AbstractEventLoop:
"""
Use loop provided or create new if not provided or closed.
Return loop passed if its provided,not closed and not running, otherwise returns new event loop.
:param loop: optional event loop
:return: asyncio event loop
"""
try:
loop = loop or asyncio.new_event_loop()
assert not loop.is_closed()
assert not loop.is_running()
except (RuntimeError, AssertionError):
loop = asyncio.new_event_loop()
return loop
示例5: async_test
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def async_test(coro):
loop: AbstractEventLoop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
def wrapper(*args, **kwargs):
current_loop: AbstractEventLoop = asyncio.get_event_loop()
return current_loop.run_until_complete(coro(*args, **kwargs))
return wrapper
示例6: __init__
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def __init__(self, address: str, loop: AbstractEventLoop = None, **kwargs):
super(BleakClientDotNet, self).__init__(address, loop, **kwargs)
# Backend specific. Python.NET objects.
self._device_info = None
self._requester = None
self._bridge = Bridge()
self._address_type = (
kwargs["address_type"]
if "address_type" in kwargs
and kwargs["address_type"] in ("public", "random")
else None
)
示例7: _notification_wrapper
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def _notification_wrapper(loop: AbstractEventLoop, func: Callable):
@wraps(func)
def dotnet_notification_parser(sender: Any, args: Any):
# Return only the UUID string representation as sender.
# Also do a conversion from System.Bytes[] to bytearray.
reader = DataReader.FromBuffer(args.CharacteristicValue)
output = Array.CreateInstance(Byte, reader.UnconsumedBufferLength)
reader.ReadBytes(output)
return loop.call_soon_threadsafe(
func, sender.Uuid.ToString(), bytearray(output)
)
return dotnet_notification_parser
示例8: __init__
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def __init__(self, address: str, loop: AbstractEventLoop = None, **kwargs):
super(BleakClientCoreBluetooth, self).__init__(address, loop, **kwargs)
self._device_info = None
self._requester = None
self._callbacks = {}
self._services = None
self._disconnected_callback = None
示例9: discover
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def discover(
timeout: float = 5.0, loop: AbstractEventLoop = None, **kwargs
) -> List[BLEDevice]:
"""Perform a Bluetooth LE Scan.
Args:
timeout (float): duration of scanning period
loop (Event Loop): Event Loop to use
"""
loop = loop if loop else asyncio.get_event_loop()
manager = CentralManagerDelegate.alloc().init()
try:
await manager.wait_for_powered_on(0.1)
except asyncio.TimeoutError:
raise BleakError("Bluetooth device is turned off")
scan_options = {"timeout": timeout}
await manager.scanForPeripherals_(scan_options)
# CoreBluetooth doesn't explicitly use MAC addresses to identify peripheral
# devices because private devices may obscure their MAC addresses. To cope
# with this, CoreBluetooth utilizes UUIDs for each peripheral. We'll use
# this for the BLEDevice address on macOS
devices = manager.devices
return list(devices.values())
示例10: create_async_task
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def create_async_task(self, loop: AbstractEventLoop) -> Awaitable:
"""
Create asyncio task for task run in asyncio loop.
:param loop: the event loop
:return: task to run in asyncio loop.
"""
示例11: create_async_task
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def create_async_task(self, loop: AbstractEventLoop) -> Awaitable:
"""Return asyncio Task for task run in asyncio loop."""
self._agent.runtime.set_loop(loop)
if not isinstance(self._agent.runtime, AsyncRuntime):
raise ValueError(
"Agent runtime is not async compatible. Please use runtime_mode=async"
)
return loop.create_task(self._agent.runtime.run_runtime())
示例12: create_async_task
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def create_async_task(self, loop: AbstractEventLoop) -> Awaitable:
"""
Return asyncio Task for task run in asyncio loop.
:param loop: abstract event loop
:return: task to run runtime
"""
self._agent.runtime.set_loop(loop)
if not isinstance(self._agent.runtime, AsyncRuntime):
raise ValueError(
"Agent runtime is not async compatible. Please use runtime_mode=async"
)
return loop.create_task(self._agent.runtime.run_runtime())
示例13: __init__
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def __init__(
self,
connections: Optional[Sequence[Connection]] = None,
default_connection_index: int = 0,
loop: Optional[AbstractEventLoop] = None,
):
"""
Initialize the connection multiplexer.
:param connections: a sequence of connections.
:param default_connection_index: the index of the connection to use as default.
This information is used for envelopes which don't specify any routing context.
If connections is None, this parameter is ignored.
:param loop: the event loop to run the multiplexer. If None, a new event loop is created.
"""
self._connections: List[Connection] = []
self._id_to_connection: Dict[PublicId, Connection] = {}
self._default_connection: Optional[Connection] = None
self._initialize_connections_if_any(connections, default_connection_index)
self._connection_status = ConnectionStatus()
self._in_queue = AsyncFriendlyQueue() # type: AsyncFriendlyQueue
self._out_queue = None # type: Optional[asyncio.Queue]
self._recv_loop_task = None # type: Optional[asyncio.Task]
self._send_loop_task = None # type: Optional[asyncio.Task]
self._default_routing = {} # type: Dict[PublicId, PublicId]
self.set_loop(loop if loop is not None else asyncio.new_event_loop())
示例14: set_loop
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def set_loop(self, loop: AbstractEventLoop) -> None:
"""
Set event loop and all event loopp related objects.
:param loop: asyncio event loop.
:return: None
"""
self._loop: AbstractEventLoop = loop
self._lock: asyncio.Lock = asyncio.Lock(loop=self._loop)
示例15: set_loop
# 需要導入模塊: from asyncio import events [as 別名]
# 或者: from asyncio.events import AbstractEventLoop [as 別名]
def set_loop(self, loop: AbstractEventLoop) -> None:
"""Set event loop and all event loopp related objects."""
self._loop: AbstractEventLoop = loop