Fix docs tests with yet another loosie-goosie
So the KBI propagates up to the actor nursery scope and also avoid running any `examples/multihost/` subdir scripts.py313_support
parent
3a0ad0f53f
commit
6a41262667
|
@ -3,20 +3,18 @@ import trio
|
||||||
import tractor
|
import tractor
|
||||||
|
|
||||||
|
|
||||||
async def sleepy_jane():
|
async def sleepy_jane() -> None:
|
||||||
uid = tractor.current_actor().uid
|
uid: tuple = tractor.current_actor().uid
|
||||||
print(f'Yo i am actor {uid}')
|
print(f'Yo i am actor {uid}')
|
||||||
await trio.sleep_forever()
|
await trio.sleep_forever()
|
||||||
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
'''
|
'''
|
||||||
Spawn a flat actor cluster, with one process per
|
Spawn a flat actor cluster, with one process per detected core.
|
||||||
detected core.
|
|
||||||
|
|
||||||
'''
|
'''
|
||||||
portal_map: dict[str, tractor.Portal]
|
portal_map: dict[str, tractor.Portal]
|
||||||
results: dict[str, str]
|
|
||||||
|
|
||||||
# look at this hip new syntax!
|
# look at this hip new syntax!
|
||||||
async with (
|
async with (
|
||||||
|
@ -25,11 +23,16 @@ async def main():
|
||||||
modules=[__name__]
|
modules=[__name__]
|
||||||
) as portal_map,
|
) as portal_map,
|
||||||
|
|
||||||
trio.open_nursery() as n,
|
trio.open_nursery(
|
||||||
|
strict_exception_groups=False,
|
||||||
|
) as tn,
|
||||||
):
|
):
|
||||||
|
|
||||||
for (name, portal) in portal_map.items():
|
for (name, portal) in portal_map.items():
|
||||||
n.start_soon(portal.run, sleepy_jane)
|
tn.start_soon(
|
||||||
|
portal.run,
|
||||||
|
sleepy_jane,
|
||||||
|
)
|
||||||
|
|
||||||
await trio.sleep(0.5)
|
await trio.sleep(0.5)
|
||||||
|
|
||||||
|
@ -41,4 +44,4 @@ if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
trio.run(main)
|
trio.run(main)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
print('trio cancelled by KBI')
|
||||||
|
|
|
@ -19,7 +19,7 @@ from tractor._testing import (
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def run_example_in_subproc(
|
def run_example_in_subproc(
|
||||||
loglevel: str,
|
loglevel: str,
|
||||||
testdir: pytest.Testdir,
|
testdir: pytest.Pytester,
|
||||||
reg_addr: tuple[str, int],
|
reg_addr: tuple[str, int],
|
||||||
):
|
):
|
||||||
|
|
||||||
|
@ -81,27 +81,37 @@ def run_example_in_subproc(
|
||||||
|
|
||||||
# walk yields: (dirpath, dirnames, filenames)
|
# walk yields: (dirpath, dirnames, filenames)
|
||||||
[
|
[
|
||||||
(p[0], f) for p in os.walk(examples_dir()) for f in p[2]
|
(p[0], f)
|
||||||
|
for p in os.walk(examples_dir())
|
||||||
|
for f in p[2]
|
||||||
|
|
||||||
if '__' not in f
|
if (
|
||||||
|
'__' not in f
|
||||||
and f[0] != '_'
|
and f[0] != '_'
|
||||||
and 'debugging' not in p[0]
|
and 'debugging' not in p[0]
|
||||||
and 'integration' not in p[0]
|
and 'integration' not in p[0]
|
||||||
and 'advanced_faults' not in p[0]
|
and 'advanced_faults' not in p[0]
|
||||||
|
and 'multihost' not in p[0]
|
||||||
|
)
|
||||||
],
|
],
|
||||||
|
|
||||||
ids=lambda t: t[1],
|
ids=lambda t: t[1],
|
||||||
)
|
)
|
||||||
def test_example(run_example_in_subproc, example_script):
|
def test_example(
|
||||||
"""Load and run scripts from this repo's ``examples/`` dir as a user
|
run_example_in_subproc,
|
||||||
|
example_script,
|
||||||
|
):
|
||||||
|
'''
|
||||||
|
Load and run scripts from this repo's ``examples/`` dir as a user
|
||||||
would copy and pasing them into their editor.
|
would copy and pasing them into their editor.
|
||||||
|
|
||||||
On windows a little more "finessing" is done to make
|
On windows a little more "finessing" is done to make
|
||||||
``multiprocessing`` play nice: we copy the ``__main__.py`` into the
|
``multiprocessing`` play nice: we copy the ``__main__.py`` into the
|
||||||
test directory and invoke the script as a module with ``python -m
|
test directory and invoke the script as a module with ``python -m
|
||||||
test_example``.
|
test_example``.
|
||||||
"""
|
|
||||||
ex_file = os.path.join(*example_script)
|
'''
|
||||||
|
ex_file: str = os.path.join(*example_script)
|
||||||
|
|
||||||
if 'rpc_bidir_streaming' in ex_file and sys.version_info < (3, 9):
|
if 'rpc_bidir_streaming' in ex_file and sys.version_info < (3, 9):
|
||||||
pytest.skip("2-way streaming example requires py3.9 async with syntax")
|
pytest.skip("2-way streaming example requires py3.9 async with syntax")
|
||||||
|
@ -127,7 +137,8 @@ def test_example(run_example_in_subproc, example_script):
|
||||||
# shouldn't eventually once we figure out what's
|
# shouldn't eventually once we figure out what's
|
||||||
# a better way to be explicit about aio side
|
# a better way to be explicit about aio side
|
||||||
# cancels?
|
# cancels?
|
||||||
and 'asyncio.exceptions.CancelledError' not in last_error
|
and
|
||||||
|
'asyncio.exceptions.CancelledError' not in last_error
|
||||||
):
|
):
|
||||||
raise Exception(errmsg)
|
raise Exception(errmsg)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue