本文整理汇总了Python中uasyncio.run方法的典型用法代码示例。如果您正苦于以下问题:Python uasyncio.run方法的具体用法?Python uasyncio.run怎么用?Python uasyncio.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类uasyncio
的用法示例。
在下文中一共展示了uasyncio.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ack_test
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def ack_test():
printexp('''message was set
message_wait 1 got message with value 0
message_wait 2 got message with value 0
Cleared ack1
Cleared ack2
Cleared message
message was set
message_wait 1 got message with value 1
message_wait 2 got message with value 1
... text omitted ...
message_wait 1 got message with value 5
message_wait 2 got message with value 5
Cleared ack1
Cleared ack2
Cleared message
I've seen attack ships burn on the shoulder of Orion...
Time to die...
''', 10)
asyncio.create_task(run_ack())
asyncio.run(ack_coro(6))
# ************ Test Lock and Message classes ************
示例2: msg_test
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def msg_test():
printexp('''Test Lock class
Test Message class
waiting for message
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 message
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
message was set
got message
Message status OK
Tasks complete
''', 5)
asyncio.run(run_message_test())
# ************ Barrier test ************
示例3: condition_test
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def condition_test():
printexp('''cond02 0 Awaiting notification.
cond02 1 Awaiting notification.
cond02 2 Awaiting notification.
cond02 3 Awaiting notification.
cond02 4 Awaiting notification.
cond02 5 Awaiting notification.
cond02 6 Awaiting notification.
cond02 5 triggered. tim = 1
cond02 6 triggered. tim = 1
cond02 3 triggered. tim = 3
cond02 4 triggered. tim = 3
cond02 1 triggered. tim = 5
cond02 2 triggered. tim = 5
cond02 0 triggered. tim = 7
cond04 99 Awaiting notification and predicate.
cond04 99 triggered. tim = 9
Done.
''', 13)
asyncio.run(cond_go())
# ************ Queue test ************
示例4: ctor_test
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def ctor_test(): # Constructor arg
s = '''
Trigger 5 sec delay
Retrigger 5 sec delay
Callback should run
cb callback
Done
'''
printexp(s, 12)
def cb(v):
print('cb', v)
d = Delay_ms(cb, ('callback',), duration=5000)
print('Trigger 5 sec delay')
d.trigger()
await asyncio.sleep(4)
print('Retrigger 5 sec delay')
d.trigger()
await asyncio.sleep(4)
print('Callback should run')
await asyncio.sleep(2)
print('Done')
示例5: isr_test
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def isr_test(): # Test trigger from hard ISR
from pyb import Timer
s = '''
Timer holds off cb for 5 secs
cb should now run
cb callback
Done
'''
printexp(s, 6)
def cb(v):
print('cb', v)
d = Delay_ms(cb, ('callback',))
def timer_cb(_):
d.trigger(200)
tim = Timer(1, freq=10, callback=timer_cb)
print('Timer holds off cb for 5 secs')
await asyncio.sleep(5)
tim.deinit()
print('cb should now run')
await asyncio.sleep(1)
print('Done')
示例6: test_sw
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [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))
run()
# Test for the switch class with a callback
示例7: test_swcb
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def test_swcb():
s = '''
close toggles red
open toggles green
'''
print('Test of switch executing callbacks.')
print(helptext)
print(s)
pin = Pin('X1', Pin.IN, Pin.PULL_UP)
red = LED(1)
green = LED(2)
sw = Switch(pin)
# Register a coro to launch on contact close
sw.close_func(toggle, (red,))
sw.open_func(toggle, (green,))
run()
# Test for the Pushbutton class (coroutines)
# Pass True to test suppress
示例8: test_btncb
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [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,))
run()
示例9: barrier_test1
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def barrier_test1():
printexp('''Running (runtime = 5s):
report instance 0 waiting
report instance 1 waiting
report instance 2 waiting
report instance 2 done
report instance 1 done
report instance 0 done
my_coro running
my_coro was cancelled.
Exact report instance done sequence may vary, but 3 instances should report
done before my_coro runs.
''', 5)
asyncio.run(bart())
# ************ Semaphore test ************
示例10: test
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def test():
try:
asyncio.run(main())
finally: # Reset uasyncio case of KeyboardInterrupt
asyncio.new_event_loop()
print('asnano_sync.test() to re-run test.')
示例11: main
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def main():
clients = {'1', '2', '3', '4'}
apps = [App(n) for n in clients] # Accept 4 clients with ID's 1-4
await server.run(clients, True, port=PORT, timeout=TIMEOUT)
示例12: run
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def run():
try:
asyncio.run(main())
except KeyboardInterrupt:
print('Interrupted')
finally:
print('Closing sockets')
server.Connection.close_all()
asyncio.new_event_loop()
示例13: main
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def main():
loop = asyncio.get_event_loop() # TEST
loop.set_exception_handler(_handle_exception) # TEST
app = App('qos')
await server.run({'qos'}, True, port=PORT, timeout=TIMEOUT)
示例14: run
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def run():
clients = {'rx', 'tx'} # Expected clients
apps = [App(name) for name in clients] # Accept 2 clients
try:
asyncio.run(server.run(clients, verbose=True, port=PORT, timeout=TIMEOUT))
except KeyboardInterrupt:
print('Interrupted')
finally:
print('Closing sockets')
server.Connection.close_all()
asyncio.new_event_loop()
示例15: barrier_test
# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import run [as 别名]
def barrier_test():
printexp('''0 0 0 Synch
1 1 1 Synch
2 2 2 Synch
3 3 3 Synch
4 4 4 Synch
''')
barrier = Barrier(3, callback, ('Synch',))
for _ in range(3):
asyncio.create_task(report(barrier))
asyncio.run(killer(2))
# ************ Semaphore test ************