How to use the tractor.current_actor function in tractor

To help you get started, we’ve selected a few tractor 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 goodboy / tractor / tests / test_multi_program.py View on Github external
async def main():
        assert not tractor.current_actor().is_arbiter
        async with tractor.open_nursery() as n:
            p1 = await n.start_actor('doggy')
            p2 = await n.start_actor('doggy')

            async with tractor.wait_for_actor('doggy') as portal:
                assert portal.channel.uid in (p2.channel.uid, p1.channel.uid)

            await n.cancel()
github goodboy / tractor / tests / test_local.py View on Github external
async def print_loop():
        # arbiter is started in-proc if dne
        assert tractor.current_actor().is_arbiter

        for i in range(10):
            nums.append(i)
            await trio.sleep(0.1)
github goodboy / tractor / tests / test_discovery.py View on Github external
async def hi():
    return the_line.format(tractor.current_actor().name)
github goodboy / tractor / tests / test_pubsub.py View on Github external
async def main():
        ss = tractor.current_actor().statespace

        async with tractor.open_nursery() as n:

            name = 'arbiter'

            if pub_actor is 'streamer':
                # start the publisher as a daemon
                master_portal = await n.start_actor(
                    'streamer',
                    rpc_module_paths=[__name__],
                )

            even_portal = await n.run_in_actor(
                'evens', subs, which=['even'], pub_actor_name=name)
            odd_portal = await n.run_in_actor(
                'odds', subs, which=['odd'], pub_actor_name=name)
github goodboy / tractor / tests / test_multi_program.py View on Github external
async def test_cancel_remote_arbiter(daemon, arb_addr):
    assert not tractor.current_actor().is_arbiter
    async with tractor.get_arbiter(*arb_addr) as portal:
        await portal.cancel_actor()

    time.sleep(0.1)
    # the arbiter channel server is cancelled but not its main task
    assert daemon.returncode is None

    # no arbiter socket should exist
    with pytest.raises(OSError):
        async with tractor.get_arbiter(*arb_addr) as portal:
            pass
github goodboy / tractor / tests / test_discovery.py View on Github external
async def test_reg_then_unreg(arb_addr):
    actor = tractor.current_actor()
    assert actor.is_arbiter
    assert len(actor._registry) == 1  # only self is registered

    async with tractor.open_nursery() as n:
        portal = await n.start_actor('actor', rpc_module_paths=[__name__])
        uid = portal.channel.uid

        async with tractor.get_arbiter(*arb_addr) as aportal:
            # this local actor should be the arbiter
            assert actor is aportal.actor

            async with tractor.wait_for_actor('actor'):
                # sub-actor uid should be in the registry
                assert uid in aportal.actor._registry
                sockaddrs = actor._registry[uid]
                # XXX: can we figure out what the listen addr will be?
github goodboy / tractor / tests / test_local.py View on Github external
async def test_self_is_registered():
    "Verify waiting on the arbiter to register itself using the standard api."
    actor = tractor.current_actor()
    assert actor.is_arbiter
    async with tractor.wait_for_actor('arbiter') as portal:
        assert portal.channel.uid[0] == 'arbiter'
github goodboy / tractor / tractor / _debug.py View on Github external
async def _hijack_stdin_relay_to_child(
    subactor_uid: Tuple[str, str]
) -> None:
    actor = tractor.current_actor()
    debug_lock = actor.statespace.setdefault(
        '_debug_lock', trio.StrictFIFOLock()
    )

    log.debug(f"Actor {subactor_uid} is waiting on stdin hijack lock")
    await debug_lock.acquire()
    log.warning(f"Actor {subactor_uid} acquired stdin hijack lock")

    # TODO: when we get to true remote debugging
    # this will deliver stdin data
    try:
        # indicate to child that we've locked stdio
        yield 'Locked'

        # wait for cancellation of stream by child
        await trio.sleep_forever()
github goodboy / tractor / examples / a_trynamic_first_scene.py View on Github external
async def hi():
    return the_line.format(tractor.current_actor().name)
github goodboy / tractor / tractor / _debug.py View on Github external
def _breakpoint(debug_func) -> Awaitable[None]:
    """``tractor`` breakpoint entry for engaging pdb machinery
    in subactors.
    """
    actor = tractor.current_actor()
    do_unlock = trio.Event()

    async def wait_for_parent_stdin_hijack(
        task_status=trio.TASK_STATUS_IGNORED
    ):

        # TODO: need a more robust check for the "root" actor
        if actor._parent_chan:
            async with tractor._portal.open_portal(
                actor._parent_chan,
                start_msg_loop=False,
                shield=True,
            ) as portal:
                # with trio.fail_after(1):
                agen = await portal.run(
                    'tractor._debug',