How to use the curio.sleep function in curio

To help you get started, we’ve selected a few curio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github caproto / caproto / tests / test_bench.py View on Github external
break
                    pvname = res.result
                    await connect_task.spawn(ctx.create_channel, pvname)

            while True:
                res = await connect_task.next_done()
                if res is None:
                    break
                curio_channel = res.result
                pvname = curio_channel.channel.name
                pvs[pvname] = curio_channel

        assert len(pvs) == len(pv_names)
        # TODO: can't successfully test as this hammers file creation; this
        # will be important to resolve...
        await curio.sleep(1)
github caproto / caproto / tests / test_repeater.py View on Github external
async def check_repeater():
            for pv in ("XF:31IDA-OP{Tbl-Ax:X1}Mtr.VAL",
                       "XF:31IDA-OP{Tbl-Ax:X2}Mtr.VAL",
                       ):
                data = await run_caget(pv)
                print(data)

            udp_sock = ca.bcast_socket()
            for i in range(3):
                print('Sending repeater register request ({})'.format(i + 1))
                udp_sock.sendto(bytes(ca.RepeaterRegisterRequest('0.0.0.0')),
                                ('127.0.0.1', REPEATER_PORT))

            await curio.sleep(1)
github virantha / bricknil / bluebrick / bluebrick.py View on Github external
# Connect all the hubs first before enabling any of them
    for hub in Hub.hubs:
        task_connect = await spawn(ble_q.connect(hub))
        await task_connect.join()

    for hub in Hub.hubs:
        # Start the peripheral listening loop in each hub
        task_listen = await spawn(hub.peripheral_message_loop())
        hub_peripheral_listen_tasks.append(task_listen)

        # Need to wait here until all the ports are set
        for name, peripheral in hub.peripherals.items():
            while peripheral.port is None:
                hub.message_info(f"Waiting for peripheral {name} to attach to a port")
                await sleep(1)

        # Start each hub
        task_run = await spawn(hub.run())
        hub_tasks.append(task_run)


    # Now wait for the tasks to finish
    for task in hub_tasks:
        await task.join()
    for task in hub_peripheral_listen_tasks:
        await task.cancel()
    await task_ble_q.cancel()

    # Print out the port information in debug mode
    for hub in Hub.hubs:
        hub.message(pprint.pformat(hub.port_info))
github allenling / magne / magne / process_worker / connection.py View on Github external
# for test
    import logging
    import os
    logger = logging.getLogger('test_connection')
    log_handler = logging.StreamHandler()
    log_format = logging.Formatter('%(levelname)s %(asctime)s %(pathname)s %(lineno)d %(message)s')
    log_handler.setFormatter(log_format)
    logger.addHandler(log_handler)
    logger.setLevel(logging.DEBUG)
    getter_queue = curio.Queue()
    putter_queue = curio.Queue()
    c = MagneConnection(['tc1', 'tc2'], logger, getter_queue, putter_queue)
    logger.info('connection pid: %s' % os.getpid())
    await c.connect()
    await c.run()
    await curio.sleep(10)
    await c.pre_close()
    await c.close()
    return
github dabeaz / curio / example.py View on Github external
async def task_b():
        lck = curio.Lock()
        async with lck:
            tid = kernel.add_task(task_a(lck))
            print('Created task', tid)
            await curio.sleep(15)
        print('Did it ever get the lock?')
github dabeaz / curio / example.py View on Github external
async def queue_putter(q):
    n = 0
    while True:
         await q.put(n)
         n += 1
         await curio.sleep(4)
github virantha / bricknil / bricknil / bricknil.py View on Github external
for hub in Hub.hubs:
        # Start the peripheral listening loop in each hub
        task_listen = await spawn(hub.peripheral_message_loop())
        hub_peripheral_listen_tasks.append(task_listen)

        # Need to wait here until all the ports are set
        # Use a faster timeout the first time (for speeding up testing)
        first_delay = True
        for name, peripheral in hub.peripherals.items():
            while peripheral.port is None:
                hub.message_info(f"Waiting for peripheral {name} to attach to a port")
                if first_delay:
                    first_delay = False
                    await sleep(0.1)
                else:
                    await sleep(1)

        # Start each hub
        task_run = await spawn(hub.run())
        hub_tasks.append(task_run)


    # Now wait for the tasks to finish
    ble_q.message_info(f'Waiting for hubs to end')

    for task in hub_tasks:
        await task.join()
    ble_q.message_info(f'Hubs end')

    for task in hub_peripheral_listen_tasks:
        await task.cancel()
    await task_ble_q.cancel()
github virantha / bricknil / examples / train_ramp.py View on Github external
async def run(self):
        self.message_info("Running")
        for i in range(2):
            self.message_info('Increasing speed')
            await self.motor.ramp_speed(80,5000)
            await sleep(6)
            self.message_info('Coming to a stop')
            await self.motor.ramp_speed(0,1000) 
            await sleep(2)
github dabeaz / curio / example.py View on Github external
async def task_a(lck):
        try:
            async with lck:
                 print('Holding a lock. Ho hum')
                 await curio.sleep(1000)
        except curio.CancelledError:
            print('Cancelled!')
            print('Wait? Am I still holding the lock or not?')
github standy66 / purerpc / src / purerpc / curio_service.py View on Github external
async def ping_writer(self):
        await self.write_event.set()
        await curio.sleep(0)