How to use the trio.run function in trio

To help you get started, we’ve selected a few trio 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 vmware / concord-bft / tests / test_skvbc_linearizability.py View on Github external
def test_healthy(self):
        """
        Run a bunch of concurrrent requests in batches and verify
        linearizability. The system is healthy and stable and no faults are
        intentionally generated.
        """
        trio.run(self._test_healthy)
github vmware / concord-bft / tests / test_skvbc_fast_path.py View on Github external
def test_fast_path_resilience_to_crashes(self):
        """
        In this test we check the fast path's resilience when up to "c" nodes fail.

        As a first step, we bring down no more than c replicas,
        triggering initially the slow path.

        Then we write a series of known K/V entries, making sure
        the fast path is eventually restored and becomes prevalent.

        Finally we check if a known K/V write has been executed.
        """
        trio.run(self._test_fast_path_resilience_to_crashes)
github python-trio / trio-amqp / examples / receive_log_direct.py View on Github external
exchange_name='direct_logs',
                    queue_name=queue_name,
                    routing_key=severity,
                )

            print(' [*] Waiting for logs. To exit press CTRL+C')

            with trio.fail_after(10):
                await channel.basic_consume(callback, queue_name=queue_name)

    except trio_amqp.AmqpClosedConnection:
        print("closed connections")
        return


trio.run(receive_log)
github guillemborrell / pycones19_tut / flappystream-worker / flappystream / worker / main.py View on Github external
def main(backend_url, nursery_url, database, user, password):
    print("Starting flappybird worker")
    connection_string = (
        f"dbname='{database}' user='{user}' host='localhost' password='{password}'"
    )

    with Sub0(dial=backend_url) as socket:
        socket.subscribe(b"") #  Subscribe to everything
        trio.run(parent, socket, connection_string, nursery_url)
github ziirish / burp-ui / burpui / misc / backend / parallel.py View on Github external
def _get_last_backup(self, name):
        """Return the last backup of a given client

        :param name: Name of the client
        :type name: str

        :returns: The last backup
        """
        return trio.run(self._async_get_last_backup, name)
github ethereum / lahja / lahja / tools / runner.py View on Github external
def __call__(self, *drivers: Driver) -> None:
        trio.run(self._engine.run_drivers, *drivers)
github goodboy / tractor / tractor / __init__.py View on Github external
This is tractor's main entry and the start point for any async actor.
    """
    # mark top most level process as root actor
    _state._runtime_vars['_is_root'] = True

    if start_method is not None:
        _spawn.try_set_start_method(start_method)

    if debug_mode:
        _state._runtime_vars['_debug_mode'] = True

    # expose internal debug module to every actor allowing
    # for use of ``await tractor.breakpoint()``
    kwargs.setdefault('rpc_module_paths', []).append('tractor._debug')

    return trio.run(_main, async_fn, args, kwargs, arbiter_addr, name)
github ethereum / trinity / scripts / discovery.py View on Github external
kademlia.Node.from_uri(enode) for enode in constants.ROPSTEN_BOOTNODES)

    ipc_path = Path(f"networking-{uuid.uuid4()}.ipc")
    networking_connection_config = ConnectionConfig(
        name=NETWORKING_EVENTBUS_ENDPOINT,
        path=ipc_path
    )

    async def run() -> None:
        socket = trio.socket.socket(family=trio.socket.AF_INET, type=trio.socket.SOCK_DGRAM)
        await socket.bind(('0.0.0.0', listen_port))
        async with TrioEndpoint.serve(networking_connection_config) as endpoint:
            service = DiscoveryService(privkey, addr, bootstrap_nodes, endpoint, socket)
            await TrioManager.run_service(service)

    trio.run(run)
github python-trio / trio-amqp / examples / new_task.py View on Github external
await channel.basic_publish(
                payload=message,
                exchange_name='',
                routing_key='task_queue',
                properties={
                    'delivery_mode': 2,
                },
            )
            print(" [x] Sent %r" % message,)

    except trio_amqp.AmqpClosedConnection:
        print("closed connections")
        return


trio.run(new_task)
github dismantl / CaseHarvester / src / mjcs / scraper.py View on Github external
def start_service(self):
        trio.run(self.__start_service, restrict_keyboard_interrupt_to_checkpoints=True)