当前位置: 首页>>代码示例>>Python>>正文


Python uasyncio.create_task方法代码示例

本文整理汇总了Python中uasyncio.create_task方法的典型用法代码示例。如果您正苦于以下问题:Python uasyncio.create_task方法的具体用法?Python uasyncio.create_task怎么用?Python uasyncio.create_task使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在uasyncio的用法示例。


在下文中一共展示了uasyncio.create_task方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def main():
    print('Press Pyboard usr button to stop test.')
    # Asynchronously flash Pyboard LED's. Because we can.
    leds = [asyncio.create_task(flash(1, 200)), asyncio.create_task(flash(2, 233))]
    # Task for each meter and GUI LED
    mtasks =[MyMeter(2, 'left').task, MyMeter(50, 'right').task, MyMeter(98, 'bass').task]
    k = Killer()
    while True:
        if await k.wait(800):  # Switch was pressed
            break
        refresh(ssd)
    for task in mtasks + leds:
        task.cancel()
    await asyncio.sleep_ms(0)
    ssd.fill(0)  # Clear display at end.
    refresh(ssd) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:18,代码来源:asnano_sync.py

示例2: publish

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def publish(self, topic, msg, retain=False, qos=0, timeout=None):
        task = None
        start = time.ticks_ms()
        while timeout is None or time.ticks_diff(time.ticks_ms(), start) < timeout:
            # Can't use wait_for because cancelling a wait_for would cancel _publishTimeout
            # Also a timeout in wait_for would cancel _publishTimeout without waiting for
            # the socket lock to be available, breaking mqtt protocol.
            if self._pub_task is None and task is None:
                task = asyncio.create_task(self._publishTimeout(topic, msg, retain, qos))
                self._pub_task = task
            elif task is not None:
                if self._pub_task != task:
                    return  # published
            await asyncio.sleep_ms(20)
        if task is not None:
            async with self.lock:
                task.cancel()
                return 
开发者ID:peterhinch,项目名称:micropython-mqtt,代码行数:20,代码来源:mqtt_as_timeout.py

示例3: start

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def start(self):
        await self.chan.ready()  # Wait for sync
        self.verbose and print('awaiting config')
        line = await self.sreader.readline()
        config = ujson.loads(line)

        self.verbose and print('Setting client config', config)
        self.cl = LinkClient(config, self.swriter, self.verbose)
        self.verbose and print('App awaiting connection.')
        await self.cl
        asyncio.create_task(self.to_server())
        asyncio.create_task(self.from_server())
        t_rep = config[_REPORT]  # Reporting interval (s)
        if t_rep:
            asyncio.create_task(self.report(t_rep))
        await self.crashdet() 
开发者ID:peterhinch,项目名称:micropython-iot,代码行数:18,代码来源:esp_link.py

示例4: await_msg

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def await_msg(self):
        while True:
            line = await self.sreader.readline()
            h, p = chr(line[0]), line[1:]  # Header char, payload
            if h == 'n':  # Normal message
                self.rxmsg.set(p)
            elif h == 'b':
                asyncio.create_task(self.bad_wifi())
            elif h == 's':
                asyncio.create_task(self.bad_server())
            elif h == 'r':
                asyncio.create_task(self.report(ujson.loads(p)))
            elif h == 'k':
                self.tim_boot.trigger(4000)  # hold off reboot (4s)
            elif h in ('u', 'd'):
                up = h == 'u'
                self._status = up
                asyncio.create_task(self.server_ok(up))
            else:
                raise ValueError('Unknown header:', h) 
开发者ID:peterhinch,项目名称:micropython-iot,代码行数:22,代码来源:app_base.py

示例5: __init__

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def __init__(self, i2c, pin, pinack, reset=None, verbose=True,
                 cr_go=False, go_args=(), cr_fail=False, f_args=()):
        super().__init__(i2c, pin, pinack, verbose, self.rxbufsize)
        self.reset = reset
        self.cr_go = cr_go
        self.go_args = go_args
        self.cr_fail = cr_fail
        self.f_args = f_args
        if reset is not None:
            reset[0].init(mode=machine.Pin.OUT, value=not (reset[1]))
        # Self measurement
        self.nboots = 0  # No. of reboots of Responder
        self.block_max = 0  # Blocking times: max
        self.block_sum = 0  # Total
        self.block_cnt = 0  # Count
        asyncio.create_task(self._run()) 
开发者ID:peterhinch,项目名称:micropython-iot,代码行数:18,代码来源:asi2c_i.py

示例6: run_ack

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def run_ack():
    message = Message()
    ack1 = Message()
    ack2 = Message()
    count = 0
    while True:
        asyncio.create_task(message_wait(message, ack1, 1))
        asyncio.create_task(message_wait(message, ack2, 2))
        message.set(count)
        count += 1
        print('message was set')
        await ack1
        ack1.clear()
        print('Cleared ack1')
        await ack2
        ack2.clear()
        print('Cleared ack2')
        message.clear()
        print('Cleared message')
        await asyncio.sleep(1) 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:22,代码来源:asyntest.py

示例7: cond_go

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def cond_go():
    ntasks = 7
    barrier = Barrier(ntasks + 1)
    t1 = asyncio.create_task(cond01())
    t3 = asyncio.create_task(cond03())
    for n in range(ntasks):
        asyncio.create_task(cond02(n, barrier))
    await barrier  # All instances of cond02 have completed
    # Test wait_for
    barrier = Barrier(2)
    asyncio.create_task(cond04(99, barrier))
    await barrier
    # cancel continuously running coros.
    t1.cancel()
    t3.cancel()
    await asyncio.sleep_ms(0)
    print('Done.') 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:19,代码来源:asyntest.py

示例8: run_ack

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def run_ack():
    message = Message()
    ack1 = asyncio.Event()
    ack2 = asyncio.Event()
    count = 0
    while True:
        asyncio.create_task(event_wait(message, ack1, 1))
        asyncio.create_task(event_wait(message, ack2, 2))
        message.set(count)
        count += 1
        print('message was set')
        await ack1.wait()
        ack1.clear()
        print('Cleared ack1')
        await ack2.wait()
        ack2.clear()
        print('Cleared ack2')
        message.clear()
        print('Cleared message')
        await asyncio.sleep(1) 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:22,代码来源:prim_test.py

示例9: cond_go

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def cond_go():
    cond = asyncio.Condition()
    ntasks = 7
    barrier = Barrier(ntasks + 1)
    t1 = asyncio.create_task(cond01_new(cond))
    t3 = asyncio.create_task(cond03_new())
    for n in range(ntasks):
        asyncio.create_task(cond02(n, cond, barrier))
    await barrier  # All instances of cond02 have completed
    # Test wait_for
    barrier = Barrier(2)
    asyncio.create_task(cond04(99, cond, barrier))
    await barrier
    # cancel continuously running coros.
    t1.cancel()
    t3.cancel()
    await asyncio.sleep(0)
    print('Done.') 
开发者ID:peterhinch,项目名称:micropython-samples,代码行数:20,代码来源:prim_test.py

示例10: gps_test

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def gps_test():
    global gps, uart  # For shutdown
    print('Initialising')
    # Adapt UART instantiation for other MicroPython hardware
    uart = pyb.UART(4, 9600, read_buf_len=200)
    # read_buf_len is precautionary: code runs reliably without it.
    sreader = asyncio.StreamReader(uart)
    swriter = asyncio.StreamWriter(uart, {})
    timer = Delay_ms(cb_timeout)
    sentence_count = 0
    gps = GPS(sreader, swriter, local_offset=1, fix_cb=callback,
                       fix_cb_args=(timer,),  msg_cb = message_cb)
    await asyncio.sleep(2)
    await gps.command(DEFAULT_SENTENCES)
    print('Set sentence frequencies to default')
    #await gps.command(FULL_COLD_START)
    #print('Performed FULL_COLD_START')
    print('awaiting first fix')
    asyncio.create_task(sat_test(gps))
    asyncio.create_task(stats(gps))
    asyncio.create_task(navigation(gps))
    asyncio.create_task(course(gps))
    asyncio.create_task(date(gps))
    await gps.data_received(True, True, True, True)  # all messages
    await change_status(gps, uart) 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:27,代码来源:ast_pbrw.py

示例11: ack_test

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [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 ************ 
开发者ID:peterhinch,项目名称:micropython-async,代码行数:27,代码来源:asyntest.py

示例12: main

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def main():
    tasks = []
    tasks.append(asyncio.create_task(meter(1, 2, 'left', 700)))
    tasks.append(asyncio.create_task(meter(2, 50, 'right', 1000)))
    tasks.append(asyncio.create_task(meter(3, 98, 'bass', 1500)))
    tasks.append(asyncio.create_task(flash(1, 200)))
    tasks.append(asyncio.create_task(flash(2, 233)))
    await killer(tasks) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:10,代码来源:asnano.py

示例13: __init__

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def __init__(self, x, text):
        CWriter.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
        wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
        wri.set_clip(True, True, False)
        super().__init__(wri, 5, x, divisions = 4, ptcolor=YELLOW, label=text,
                         style=Meter.BAR, legends=('0.0', '0.5', '1.0'))
        self.led = LED(wri, ssd.height - 16 - wri.height, x, bdcolor=YELLOW, label ='over')
        self.task = asyncio.create_task(self._run()) 
开发者ID:peterhinch,项目名称:micropython-nano-gui,代码行数:10,代码来源:asnano_sync.py

示例14: start

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def start(self):  # Apps must implement a synchronous start method
        asyncio.create_task(self.receiver())
        asyncio.create_task(self.sender())

    # If server is running s_app_cp.py it sends
    # [approx app uptime in secs/5, echoed count, echoed 99] 
开发者ID:peterhinch,项目名称:micropython-iot,代码行数:8,代码来源:pb_client.py

示例15: reboot

# 需要导入模块: import uasyncio [as 别名]
# 或者: from uasyncio import create_task [as 别名]
def reboot(self):
        self.verbose and print('AppBase reboot')
        if self.chan.reset is None:  # No config for reset
            raise OSError('Cannot reset ESP8266.')
        asyncio.create_task(self.chan.reboot())  # Hardware reset board
        self.tim_boot.stop()  # No more reboots
        if not self.wlock.locked():  # Prevent user writes
            await self.wlock.acquire() 
开发者ID:peterhinch,项目名称:micropython-iot,代码行数:10,代码来源:app_base.py


注:本文中的uasyncio.create_task方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。