forked from goodboy/tractor
1
0
Fork 0
Commit Graph

709 Commits (400b7ae1240d8e00106d4fc1f27bbc38f90836e2)

Author SHA1 Message Date
Tyler Goodlet 400b7ae124 Add per actor debug mode toggle 2021-06-14 09:26:42 -04:00
Tyler Goodlet d1beb1035d Support sync code breakpointing via built-in
Override `breakpoint()` for sync code making it work
properly with `trio` as per:

https://github.com/python-trio/trio/issues/1155#issuecomment-742964018

Relates to #193
2021-06-14 09:26:42 -04:00
Tyler Goodlet 3b46be99ae Pass func refs 2021-06-14 09:26:42 -04:00
Tyler Goodlet 476418cfc6 Shush the linter 2021-06-14 09:26:42 -04:00
Tyler Goodlet 61e5284461 Add initial infected asyncio error propagation test 2021-06-14 09:26:42 -04:00
Tyler Goodlet f4e4cc1418 Raise any asyncio errors if in trio task on cancel 2021-06-14 09:26:42 -04:00
Tyler Goodlet 3e219f76ab Raise from asyncio error; fixes mypy 2021-06-14 09:26:42 -04:00
Tyler Goodlet 44f1b6ca95 Tweak log msg 2021-06-14 09:26:42 -04:00
Tyler Goodlet 19c02b920f Log error 2021-06-14 09:26:42 -04:00
Tyler Goodlet 94927948a9 Support asyncio actors with the trio spawner backend 2021-06-14 09:26:42 -04:00
Tyler Goodlet da16149cad Revert removal of `infect_asyncio` in nursery start methods 2021-06-14 09:26:42 -04:00
Tyler Goodlet cad78d8d0a Attempt to make mypy happy.. 2021-06-14 09:26:42 -04:00
Tyler Goodlet 74d4baa489 Add an obnoxious error message on internal failures 2021-06-14 09:26:42 -04:00
Tyler Goodlet d182fa7036 Wow, fix all the broken async func invoking code..
Clearly this wasn't developed against a task that spawned just an async
func in `asyncio`.. Fix all that and remove a bunch of unnecessary func
layers. Add provisional support for the target receiving the `to_trio`
and `from_trio` channels and for the @tractor.stream marker.
2021-06-14 09:26:42 -04:00
Tyler Goodlet a1cae99e23 Drop entrypoints from `Actor` 2021-06-14 09:26:42 -04:00
Tyler Goodlet 7df6fe54f0 Move asyncio guest mode entrypoint to `to_asyncio`
The function is useful if you want to run the "main process" under
`asyncio`. Until `trio` core wraps this better we'll keep our own copy
in the interim (there's a new "inside-out-guest" mode almost on
mainline so hang tight).
2021-06-14 09:26:42 -04:00
Tyler Goodlet 88c449ca2e Propagate any spawned `asyncio` task error upwards
This should mostly maintain top level SC principles for any task spawned
using `tractor.to_asyncio.run()`. When the `asyncio` task completes make
sure to cancel the pertaining `trio` cancel scope and raise any error
that may have resulted.

Resolves #120
2021-06-14 09:26:42 -04:00
Tyler Goodlet 8ce7d4fbe2 Add a @pub kwarg to allow specifying a "startup response message" 2021-06-14 09:26:42 -04:00
Tyler Goodlet 5b65dd8871 Add streaming decode support for `msgspec`
Add a `tractor._ipc.MsgspecStream` type which can be swapped in for
`msgspec` serialization transparently. A small msg-length-prefix framing
is implemented as part of the type and we use
`tricycle.BufferedReceieveStream` to handle buffering logic for the
underlying transport.

Notes:
- had to force cast a few more list  -> tuple spots due to no native
  `tuple`decode-by-default in `msgspec`: https://github.com/jcrist/msgspec/issues/30
- the framing can be understood by this protobuf walkthrough:
  https://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers
- `tricycle` becomes a new dependency
2021-06-14 09:26:25 -04:00
Tyler Goodlet 2d36cf478d Always cast arbiter addr to tuple 2021-06-14 09:26:25 -04:00
Tyler Goodlet 6c2e0630cd Add `tricycle` and `msgspec` deps 2021-06-14 09:26:25 -04:00
Tyler Goodlet c83b9cc940 Try out `msgspec` in our msgpack stream channel
Can only really use an encoder currently since there is no streaming api
in `msgspec` as of currently. See jcrist/msgspec#27.

Not sure if any encoding speedups are currently noticeable especially
without any validation going on yet XD.

First experiments toward #196
2021-06-14 09:26:25 -04:00
Tyler Goodlet cc2b9d20a4 Cast to tuples for all uids explicitly 2021-06-14 09:26:25 -04:00
Tyler Goodlet 634dee1a3c Move debugger wait inside OCA nursery 2021-06-14 09:25:56 -04:00
Tyler Goodlet e1935051d2 Don't shield debugger status wait; it causes hangs 2021-06-14 09:25:56 -04:00
Tyler Goodlet 12afdb8228 Catch and delay errors in the root if debugger is active 2021-06-14 09:25:56 -04:00
Tyler Goodlet 664c3d6b21 Don't shield on root cancel it can causes hangs 2021-06-14 09:25:56 -04:00
Tyler Goodlet d0cf64361a Experiment: only disable SIGINT handling in children 2021-06-14 09:25:56 -04:00
Tyler Goodlet 48017e52ab Don't kill root's immediate children when in debug
If the root calls `trio.Process.kill()` on immediate child proc teardown
when the child is using pdb, we can get stdstreams clobbering that
results in a pdb++ repl where the user can't see what's been typed. Not
killing such children on cancellation / error seems to resolve this
issue whilst still giving reliable termination. For now, code that
special path until a time it becomes a problem for ensuring zombie
reaps.
2021-06-14 09:25:56 -04:00
Tyler Goodlet dded1f11ff Add debug example that causes pdb stdin clobbering 2021-06-14 09:25:56 -04:00
Tyler Goodlet caaf15b75a Always raise end of channel ; see if it fixes CI 2021-06-14 09:25:21 -04:00
Tyler Goodlet 6c039f7581 Modernize streaming tests 2021-06-14 09:25:21 -04:00
Tyler Goodlet af94ca9b6a Speedup the dynamic pubsub test 2021-06-14 09:25:21 -04:00
Tyler Goodlet db1e3dc353 Add detailed ``@tractor.context`` cancellation/termination tests 2021-06-14 09:25:21 -04:00
Tyler Goodlet ec8743ebc3 Drop trailing comma 2021-06-14 09:25:21 -04:00
Tyler Goodlet b95c6efbe9 Adjustments for non-frozen context dataclass change 2021-06-14 09:25:21 -04:00
Tyler Goodlet 3988a24e57 Wait for debugger lock task context termination 2021-06-14 09:25:21 -04:00
Tyler Goodlet 2e71914cb7 Fix exception typing 2021-06-14 09:25:21 -04:00
Tyler Goodlet 00c06a00ae Explicitly formalize context/streaming teardown
Add clear teardown semantics for `Context` such that the remote side
cancellation propagation happens only on error or if client code
explicitly requests it (either by exit flag to `Portal.open_context()`
or by manually calling `Context.cancel()`).  Add `Context.result()`
to wait on and capture the final result from a remote context function;
any lingering msg sequence will be consumed/discarded.

Changes in order to make this possible:
- pass the runtime msg loop's feeder receive channel in to the context
  on the calling (portal opening) side such that a final 'return' msg
  can be waited upon using `Context.result()` which delivers the final
  return value from the callee side `@tractor.context` async function.
- always await a final result from the target context function in
  `Portal.open_context()`'s `__aexit__()` if the context has not
  been (requested to be) cancelled by client code on block exit.
- add an internal `Context._cancel_called` for context "cancel
  requested" tracking (much like `trio`'s cancel scope).
- allow flagging a stream as terminated using an internal
  `._eoc` flag which will mark the stream as stopped for iteration.
- drop `StopAsyncIteration` catching in `.receive()`; it does
  nothing.
2021-06-14 09:25:21 -04:00
Tyler Goodlet 09a567c857 Specially raise a `ContextCancelled` for a task-context rpc 2021-06-14 09:25:21 -04:00
Tyler Goodlet d7ab01dc20 Expose streaming components at top level 2021-06-14 09:25:21 -04:00
Tyler Goodlet 4ed38281b3 Add a specially handled `ContextCancelled` error 2021-06-14 09:25:21 -04:00
Tyler Goodlet 25c159961b Add a multi-task streaming test 2021-06-14 09:25:21 -04:00
Tyler Goodlet 8f25f2d2fa Avoid mutate on iterate race 2021-06-14 09:25:21 -04:00
Tyler Goodlet 8297e765c1 Only close recv chan if we get a ref 2021-06-14 09:25:21 -04:00
Tyler Goodlet 0090a57681 Add error case 2021-06-14 09:25:21 -04:00
Tyler Goodlet 582eae699a Support no arg to `Context.started()` like trio 2021-06-14 09:25:21 -04:00
Tyler Goodlet b0bcb430bf Fix up var naming and typing 2021-06-14 09:25:21 -04:00
Tyler Goodlet 7eb76e8d97 Only send stop msg if not received from far end 2021-06-14 09:25:21 -04:00
Tyler Goodlet 55bea3ca17 Expose msg stream types at top level 2021-06-14 09:25:21 -04:00