forked from goodboy/tractor
1
0
Fork 0
Commit Graph

688 Commits (11d471a4cd72302bc47372d208bb12a3f382e6e6)

Author SHA1 Message Date
Tyler Goodlet 11d471a4cd Add detailed ``@tractor.context`` cancellation/termination tests 2021-07-01 15:04:58 -04:00
Tyler Goodlet b63ccf0007 Drop trailing comma 2021-07-01 15:04:58 -04:00
Tyler Goodlet d896d84b28 Adjustments for non-frozen context dataclass change 2021-07-01 15:04:58 -04:00
Tyler Goodlet fc8d02f963 Wait for debugger lock task context termination 2021-07-01 15:04:58 -04:00
Tyler Goodlet 3b48f89056 Fix exception typing 2021-07-01 15:04:57 -04:00
Tyler Goodlet a146034cb7 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-07-01 15:04:57 -04:00
Tyler Goodlet 0e6f017929 Specially raise a `ContextCancelled` for a task-context rpc 2021-07-01 15:04:56 -04:00
Tyler Goodlet 0d8a5506da Expose streaming components at top level 2021-07-01 15:02:47 -04:00
Tyler Goodlet fed927d00f Add a specially handled `ContextCancelled` error 2021-07-01 15:02:45 -04:00
Tyler Goodlet 1c7c9da99c Add a multi-task streaming test 2021-07-01 15:02:10 -04:00
Tyler Goodlet b6dd58b1cf Avoid mutate on iterate race 2021-07-01 15:02:10 -04:00
Tyler Goodlet 9b70f5d312 Only close recv chan if we get a ref 2021-07-01 15:02:10 -04:00
Tyler Goodlet b92ed701bd Add error case 2021-07-01 15:02:10 -04:00
Tyler Goodlet 4c712a8e47 Support no arg to `Context.started()` like trio 2021-07-01 15:02:10 -04:00
Tyler Goodlet 6bec0ddf0c Fix up var naming and typing 2021-07-01 15:02:10 -04:00
Tyler Goodlet 7192654d51 Only send stop msg if not received from far end 2021-07-01 15:02:10 -04:00
Tyler Goodlet 9d5f193dfd Expose msg stream types at top level 2021-07-01 15:02:10 -04:00
Tyler Goodlet 8b13dc4967 Add dynamic pubsub test using new bidir stream apis 2021-07-01 15:02:10 -04:00
Tyler Goodlet 6f62277c82 Use context for remote debugger locking
A context is the natural fit (vs. a receive stream) for locking the root
proc's tty usage via it's `.started()` sync point. Simplify the
`_breakpoin()` routine to be a simple async func instead of all this
"returning a coroutine" stuff from before we decided that
`tractor.breakpoint()` must be async. Use `runtime` level for locking
logging making it easier to trace.
2021-07-01 15:02:10 -04:00
Tyler Goodlet 207a88e3a8 Be more pedantic with error handling 2021-07-01 15:02:10 -04:00
Tyler Goodlet 2905127dc7 Fix typing 2021-07-01 15:02:10 -04:00
Tyler Goodlet 7d9a551f77 Parametrize with async for style tests 2021-07-01 15:02:10 -04:00
Tyler Goodlet 66d18be2ec Support passing `shield` at stream contruction 2021-07-01 15:02:10 -04:00
Tyler Goodlet bc689427ef Add basic test set 2021-07-01 15:02:10 -04:00
Tyler Goodlet 490cc8ac53 Cancel scope on stream consumer completion 2021-07-01 15:02:10 -04:00
Tyler Goodlet cdafdde092 Expose `@context` decorator at top level 2021-07-01 15:02:10 -04:00
Tyler Goodlet 2870828c34 Add initial bi-directional streaming
This mostly adds the api described in
https://github.com/goodboy/tractor/issues/53#issuecomment-806258798

The first draft summary:
- formalize bidir steaming using the `trio.Channel` style interface
  which we derive as a `MsgStream` type.
- add `Portal.open_context()` which provides a `trio.Nursery.start()`
  remote task invocation style for setting up and tearing down tasks
  contexts in remote actors.
- add a distinct `'started'` message to the ipc protocol to facilitate
  `Context.start()` with a first return value.
- for our `ReceiveMsgStream` type, don't cancel the remote task in
  `.aclose()`; this is now done explicitly by the surrounding `Context`
   usage: `Context.cancel()`.
- streams in either direction still use a `'yield'` message keeping the
  proto mostly symmetric without having to worry about which side is the
  caller / portal opener.
- subtlety: only allow sending a `'stop'` message during a 2-way
  streaming context from `ReceiveStream.aclose()`, detailed comment
  with explanation is included.

Relates to #53
2021-07-01 15:02:10 -04:00
Tyler Goodlet 76f07898d9 Mypy fixes to enforce uid tuple 2021-07-01 14:52:52 -04:00
Tyler Goodlet 1e49066b16 Not sure exactly, but we're getting a top level multierr now? 2021-07-01 10:10:56 -04:00
Tyler Goodlet b1de90b175 Fix py version classifier 2021-07-01 09:54:59 -04:00
Tyler Goodlet 2bd6bbc1b7 Pkg `msgpec` as optional dep, load transport type if importable 2021-07-01 09:41:23 -04:00
Tyler Goodlet 700f09ce9b Accept transport closed error during handshake and msg loop 2021-07-01 09:00:46 -04:00
Tyler Goodlet d8dcee3713 Drop happy eyeballs inf delay 2021-07-01 09:00:19 -04:00
Tyler Goodlet 6463aa1559 Add our own "transport closed" signal
This change some super old (and bad) code from the project's very early
days. For some redic reason i must have thought masking `trio`'s
internal stream / transport errors and a TCP EOF as `StopAsyncIteration`
somehow a good idea. The reality is you probably
want to know the difference between an unexpected transport error
and a simple EOF lol. This begins to resolve that by adding our own
special `TransportClosed` error to signal the "graceful" termination of
a channel's underlying transport. Oh, and this builds on the `msgspec`
integration which helped shed light on the core issues here B)
2021-07-01 09:00:14 -04:00
Tyler Goodlet 39453e43e0 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-07-01 08:57:15 -04:00
Tyler Goodlet d89e632a16 Always cast arbiter addr to tuple 2021-07-01 08:57:15 -04:00
Tyler Goodlet b38b4fe188 Add `tricycle` and `msgspec` deps 2021-07-01 08:57:15 -04:00
Tyler Goodlet e6aecf2ae5 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-07-01 08:57:15 -04:00
Tyler Goodlet b44652c5d5 Cast to tuples for all uids explicitly 2021-07-01 08:57:15 -04:00
Tyler Goodlet 44d7988204 New docs theme hotfix 2021-06-14 08:10:59 -04:00
goodboy e98302212a
Merge pull request #211 from goodboy/new_docs_polish
New docs theme, readme actors rant.
2021-06-14 07:33:02 -04:00
Tyler Goodlet 0301d105dd Better rant flow as per suggestions 2021-06-14 06:41:10 -04:00
Tyler Goodlet 4ee7db338d Fill out the rant a bit more 2021-06-14 06:31:16 -04:00
Tyler Goodlet 558d546c8f Bump readme for #210 2021-06-14 06:31:16 -04:00
Tyler Goodlet 5528a4eb45 Attempt configuring sphinx-book-theme 2021-06-14 06:31:16 -04:00
Tyler Goodlet fb23a9d8d4 Try out sphinx-book-theme 2021-06-14 06:31:16 -04:00
goodboy f48548ab94
Merge pull request #197 from goodboy/drop_run
Drop run
2021-05-07 12:02:23 -04:00
Tyler Goodlet 73e123bac7 Fix line length 2021-05-07 11:21:40 -04:00
Tyler Goodlet 2b4cf59ee1 Drop sleep 2021-05-07 11:21:40 -04:00
Tyler Goodlet 0551756e22 Use trio.run() in windows tests 2021-05-07 11:21:40 -04:00