本文整理汇总了Python中uasyncio.get_event_loop方法的典型用法代码示例。如果您正苦于以下问题:Python uasyncio.get_event_loop方法的具体用法?Python uasyncio.get_event_loop怎么用?Python uasyncio.get_event_loop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uasyncio
的用法示例。
在下文中一共展示了uasyncio.get_event_loop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: launch
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def launch(func, tup_args):
res = func(*tup_args)
if isinstance(res, type_coro):
loop = asyncio.get_event_loop()
loop.create_task(res)
# To access a lockable resource a coro should issue
# async with lock_instance:
# access the locked resource
# Alternatively:
# await lock.acquire()
# try:
# do stuff with locked resource
# finally:
# lock.release
# Uses normal scheduling on assumption that locks are held briefly.
示例2: start
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def start(self, user_task=None, awaitable=None):
loop = asyncio.get_event_loop()
while True:
if not self._running: # Restarting
self.lstrx = [] # Clear down queues
self.lsttx = []
self._synchronised = False
loop.create_task(self._run()) # Reset target (if possible)
while not self._synchronised: # Wait for sync
await asyncio.sleep_ms(100)
if user_task is None:
while self._running:
await asyncio.sleep_ms(100)
else:
await user_task(self) # User task must quit on timeout
# If it quit for other reasons force a t/o exception
self.stop()
await asyncio.sleep_ms(0)
if awaitable is not None: # User code may use an ExitGate
await awaitable # to ensure all coros have quit
# Can be used to force a failure
示例3: test_sw
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def test_sw():
s = '''
close pulses green
open pulses red
'''
print('Test of switch scheduling coroutines.')
print(helptext)
print(s)
pin = Pin('X1', Pin.IN, Pin.PULL_UP)
red = LED(1)
green = LED(2)
sw = Switch(pin)
# Register coros to launch on contact close and open
sw.close_func(pulse, (green, 1000))
sw.open_func(pulse, (red, 1000))
loop = asyncio.get_event_loop()
loop.run_until_complete(killer())
# Test for the switch class with a callback
示例4: test_btncb
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def test_btncb():
s = '''
press toggles red
release toggles green
double click toggles yellow
long press toggles blue
'''
print('Test of pushbutton executing callbacks.')
print(helptext)
print(s)
pin = Pin('X1', Pin.IN, Pin.PULL_UP)
red = LED(1)
green = LED(2)
yellow = LED(3)
blue = LED(4)
pb = Pushbutton(pin)
pb.press_func(toggle, (red,))
pb.release_func(toggle, (green,))
pb.double_func(toggle, (yellow,))
pb.long_func(toggle, (blue,))
loop = asyncio.get_event_loop()
loop.run_until_complete(killer())
示例5: event_test
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def event_test():
printexp('''Test Lock class
Test Event class
waiting for event
run_lock 1 waiting for lock
run_lock 1 acquired lock
run_lock 2 waiting for lock
run_lock 3 waiting for lock
Waiting 5 secs before setting event
run_lock 1 released lock
run_lock 2 acquired lock
run_lock 2 released lock
run_lock 3 acquired lock
run_lock 3 released lock
event was set
got event
Event status OK
Tasks complete
''', 5)
asyncio.get_event_loop().run_until_complete(run_event_test())
# ************ Barrier test ************
示例6: run
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def run(self, host="127.0.0.1", port=8081, debug=False, lazy_init=False, log=None):
if log is None and debug >= 0:
import ulogging
log = ulogging.getLogger("picoweb")
if debug > 0:
log.setLevel(ulogging.DEBUG)
self.log = log
gc.collect()
self.debug = int(debug)
self.init()
if not lazy_init:
for app in self.mounts:
app.init()
loop = asyncio.get_event_loop()
if debug > 0:
print("* Running on http://%s:%s/" % (host, port))
loop.create_task(asyncio.start_server(self._handle, host, port))
loop.run_forever()
loop.close()
示例7: __init__
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def __init__(self, adc, adc_multi, voltage_calibration_0, pH_calibration_value_0,
voltage_calibration_1, pH_calibration_value_1,
precision=2, interval=None, mqtt_topic=None,
friendly_name=None, discover=True):
# This makes it possible to use multiple instances of MySensor
global _unit_index
_unit_index += 1
super().__init__(COMPONENT_NAME, __version__, _unit_index, discover)
self._interval = interval or config.INTERVAL_SENSOR_PUBLISH
self._topic = mqtt_topic
self._frn = friendly_name
self._adc = ADC(adc)
self._adc_multi = adc_multi
self.__ph = None
self._prec = int(precision)
self._v0 = voltage_calibration_0
self._v1 = voltage_calibration_1
self._ph0 = pH_calibration_value_0
self._ph1 = pH_calibration_value_1
gc.collect()
if self._interval > 0: # if interval==-1 no loop will be started
asyncio.get_event_loop().create_task(self._loop())
示例8: changeMode
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def changeMode(self, topic, msg, retain):
print("changeMode", topic, msg, retain, self._repeating_mode)
if msg not in _mqtt.payload_on and msg not in _mqtt.payload_off:
raise ValueError("unsupported payload {!r}".format(msg))
if msg in _mqtt.payload_on:
if self._repeating_mode is True:
# already on
return True
elif self._repeating_mode is False:
await super().on_message(self._topic, "OFF", retain)
self._off_coro = self._repeating()
asyncio.get_event_loop().create_task(self._off_coro)
elif msg in _mqtt.payload_off:
if self._off_coro is not None:
asyncio.cancel(self._off_coro) # will shut down pump
self._off_coro = None
if self._repeating_mode is True:
return True
elif self._repeating_mode is False:
await super().on_message(self._topic, "OFF", retain)
return True
return True
示例9: _connected_handler
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def _connected_handler(self, client):
try:
await self.publish(self.getDeviceTopic(config.MQTT_AVAILABILITY_SUBTOPIC), "online",
qos=1, retain=True)
# if it hangs here because connection is lost, it will get canceled when reconnected.
if self.__first_connect is True:
# only log on first connection, not on reconnect as nothing has changed here
await _log.asyncLog("info", str(os.name if platform == "linux" else os.uname()))
await _log.asyncLog("info", "Client version: {!s}".format(config.VERSION))
self.__first_connect = False
elif self.__first_connect is False:
await _log.asyncLog("debug", "Reconnected")
# resubscribe topics because clean session is used
if self._sub_coro is not None:
asyncio.cancel(self._sub_coro)
self._sub_coro = self._subscribeTopics()
asyncio.get_event_loop().create_task(self._sub_coro)
for cb in self._reconnected_subs:
res = cb(client)
if type(res) == type_gen:
await res
self._connected_coro = None
except asyncio.CancelledError:
if self._sub_coro is not None:
asyncio.cancel(self._sub_coro)
示例10: log
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def log(name, level, *message, local_only=False, return_only=False, timeout=None):
if level == "debug" and not config.DEBUG: # ignore debug messages if debug is disabled
return
if hasattr(config, "RTC_SYNC_ACTIVE") and config.RTC_SYNC_ACTIVE:
if hasattr(time, "strftime"):
print("[{}]".format(time.strftime("%Y-%m-%d %H:%M:%S")), "[{}]".format(name),
"[{}]".format(level), *message)
else:
t = time.localtime()
print("[{}-{:02d}-{:02d} {:02d}:{:02d}:{:02d}]".format(*t), "[{}]".format(name),
"[{}]".format(level), *message)
else:
print("[{!s}] [{!s}]".format(name, level), *message)
if return_only:
return
if not local_only:
asyncio.get_event_loop().create_task(asyncLog(name, level, *message, timeout=timeout,
await_connection=True))
示例11: __init__
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def __init__(self, component_name, version, unit_index: int, discover=True):
self._next_component = None # needed to keep a list of registered components
global _components
if _components is None:
_components = self
else:
c = _components
while c is not None:
if c._next_component is None:
c._next_component = self
break
c = c._next_component
# Workaround to prevent every component object from creating a new asyncio task for
# network oriented initialization as this would lead to an asyncio queue overflow.
global _init_queue_start
if _init_queue_start is None:
_init_queue_start = self
asyncio.get_event_loop().create_task(self.__initNetworkProcess())
self.COMPONENT_NAME = component_name
self.VERSION = version
self._count = unit_index
self.__discover = discover
示例12: cbgreen
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def cbgreen(command, text):
loop = asyncio.get_event_loop()
loop.create_task(pulse(green, 500))
# The user_start callback. See docs 2.3.5.
示例13: start
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def start(mqtt_link):
global reset_count
mqtt_link.subscribe('green', qos, cbgreen) # LED control qos 1
loop = asyncio.get_event_loop()
loop.create_task(asyn.Cancellable(publish, mqtt_link, 10)()) # Publish a count every 10 seconds
loop.create_task(pulse(blue)) # Flash blue LED each time we restart ESP8266
reset_count += 1
示例14: start
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def start(mqtt_link):
global reset_count
mqtt_link.subscribe('green', qos, cbgreen) # LED control qos 1
mqtt_link.wifi_handler(cbnet, mqtt_link) # Detect WiFi changes
loop = asyncio.get_event_loop()
loop.create_task(asyn.Cancellable(publish, mqtt_link, 10)()) # Publish a count every 10 seconds
loop.create_task(pulse(blue)) # Flash blue LED each time we restart ESP8266
reset_count += 1
示例15: _reconnect
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import get_event_loop [as 别名]
def _reconnect(self): # Schedule a reconnection if not underway.
if self._isconnected:
self._isconnected = False
self.close()
loop = asyncio.get_event_loop()
loop.create_task(self._wifi_handler(False)) # User handler.
# Await broker connection.