forked from goodboy/tractor
1
0
Fork 0

Add func type checking to `.run_in_actor()`

stream_contexts
Tyler Goodlet 2021-04-28 11:39:26 -04:00
parent 86fc418050
commit f59346d854
1 changed files with 9 additions and 0 deletions

View File

@ -2,6 +2,7 @@
``trio`` inspired apis and helpers ``trio`` inspired apis and helpers
""" """
from functools import partial from functools import partial
import inspect
import multiprocessing as mp import multiprocessing as mp
from typing import Tuple, List, Dict, Optional from typing import Tuple, List, Dict, Optional
import typing import typing
@ -136,6 +137,14 @@ class ActorNursery:
# use the run_in_actor nursery # use the run_in_actor nursery
nursery=self._ria_nursery, nursery=self._ria_nursery,
) )
# XXX: don't allow stream funcs
if not (
inspect.iscoroutinefunction(fn) and
not getattr(fn, '_tractor_stream_function', False)
):
raise TypeError(f'{fn} must be an async function!')
# this marks the actor to be cancelled after its portal result # this marks the actor to be cancelled after its portal result
# is retreived, see logic in `open_nursery()` below. # is retreived, see logic in `open_nursery()` below.
self._cancel_after_result_on_exit.add(portal) self._cancel_after_result_on_exit.add(portal)