Commit Graph

1232 Commits (8a70a52ff901e1fe56ef3d84526b66872c8bcd05)

Author SHA1 Message Date
Christian López Barrón 2138d55a60 increased trio.sleep time for other actors to spawn 2019-03-13 21:32:45 +11:00
Christian López Barrón b992dc19e3 moved assert statement for name on try_set_start_method after its autoset 2019-03-13 21:32:45 +11:00
Christian López Barrón efffca371a pytest_generate_tests remove `fork` only if it's in list 2019-03-13 21:32:45 +11:00
Tyler Goodlet 63d067792c Rename `StreamQueue` to `MsgpackStream`
Prepares for other possible interchange formats plus it wasn't really
a queue, just a TCP stream wrapper + `msgpack` interchange.
2019-03-12 01:22:46 -04:00
tgoodlet 8c5337c5ca
Merge pull request #67 from tgoodlet/docs_example_fixes
Docs example fixes
2019-03-11 16:10:00 -04:00
tgoodlet ddf467acf5
Merge pull request #68 from tgoodlet/close_mem_chans
Use "clean channel shutdown" in streaming example
2019-03-11 16:09:00 -04:00
Tyler Goodlet 0b520c7bee Update streaming example in docs 2019-03-10 22:13:21 -04:00
Tyler Goodlet 9a780485dc Use "clean channel shutdown" in streaming example
Resolves #65
2019-03-10 22:08:50 -04:00
Tyler Goodlet 322145684b Pass an actor name to `main()` in discovery ex
Resolves #41
2019-03-10 15:59:59 -04:00
Tyler Goodlet e560322b9b Fix actor misnaming in 2nd spawning example
Resolves #64
2019-03-10 15:56:20 -04:00
goodboy c0276c85df
Merge pull request #61 from tgoodlet/spawn_method_support
Spawn method support
2019-03-08 20:11:40 -05:00
Tyler Goodlet b70f4eafcb Flip tests to use `start_method` kwarg 2019-03-08 20:06:16 -05:00
Tyler Goodlet c3daf73112 Document the mp start method more explicitly 2019-03-08 20:01:42 -05:00
Tyler Goodlet 8eb138b8a7 Add Windows *gotchas* section
Resolves #61
2019-03-07 18:28:22 -05:00
Tyler Goodlet 49b711fb5f Be more stingy about "actor model" 2019-03-06 22:57:27 -05:00
Tyler Goodlet dc5cc040e6 Try to support waiting on Windows processes
This pokes around a little in `trio` hazmat but it *should
work* as it piggy backs on the new cross platform subprocess support.

Relates to #59
2019-03-06 21:24:23 -05:00
Tyler Goodlet d6ca722bcc Sprinkle `spawn_method` fixture throughout tests 2019-03-06 00:37:02 -05:00
Tyler Goodlet 483ae42a46 Add a `spawn_method` dynamic fixture 2019-03-06 00:36:37 -05:00
Tyler Goodlet 7014a07986 Add "spawn" start method support
Add full support for using the "spawn" process starting method as per:
https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods

Add a  `spawn_method` argument to `tractor.run()` for specifying the
desired method explicitly. By default use the "fastest" method available.
On *nix systems this is the original "forkserver" method.

This should be the solution to getting windows support!

Resolves #60
2019-03-06 00:29:07 -05:00
Tyler Goodlet d75739e9c7 Factor process creation into a separate factory
Make a `_spawn` module for encapsulating all the `multiprocessing`
"spawn method" stuff and factor current forkserver steps into it.
2019-03-05 18:52:19 -05:00
goodboy a927966170
Merge pull request #56 from tgoodlet/trio_memchans
Use trio memory channels!
2019-02-20 21:24:47 -05:00
Tyler Goodlet fd4e126e1f Adjust streaming ex to use memory channel 2019-02-17 10:04:27 -05:00
Tyler Goodlet 78ddd33e3a Move to `trio.CancelScope` 2019-02-16 14:25:06 -05:00
Tyler Goodlet 02e0c0e1a4 `trio.ClosedResourceError is deprecated 2019-02-16 14:05:24 -05:00
Tyler Goodlet fe1c4dbc4c mpypy and docs fixups 2019-02-16 14:05:03 -05:00
Tyler Goodlet 85a0700716 Add back line that breaks with async gens 2019-02-15 22:10:55 -05:00
Tyler Goodlet 616192d853 Don't use async gen functions for the stream API
As mentioned in prior commits there's currently a bug in Python that
make async gens **not** task safe. Since this is the core cause of almost
all recent problems, instead implement our own async iterator derivative of
`trio.abc.ReceiveChannel` by wrapping a `trio._channel.MemoryReceiveChannel`.
This fits more natively with the memory channel API in ``trio`` and adds
potentially more flexibility for possible bidirectional inter-actor streaming
in the future.

Huge thanks to @oremanj and of course @njsmith for guidance on this one!
2019-02-15 21:59:42 -05:00
Tyler Goodlet b91d13cfea Use local actor var 2019-02-15 17:11:26 -05:00
Tyler Goodlet 51f082fff7 Use mem chan in streaming tests 2019-02-15 17:10:57 -05:00
Tyler Goodlet 41c202db68 Add a multi-task subscriber test
In combination with `.aclose()`-ing the async gen instance returned from
`Portal.run()` this demonstrates the python bug:
https://bugs.python.org/issue32526

I've commented out the line that triggers the bug for now since this
case provides motivation for adding our own `trio.abc.ReceiveMemoryChannel`
implementation to be used instead of async gens directly (returned from
`Portal.run()`) since the latter is **not** task safe.
2019-02-15 17:04:41 -05:00
Tyler Goodlet 61680b3729 Use a receive mem channel inside portals
For now stop `.aclose()`-ing all async gens on portal close since it can
cause hangs and other weird behaviour if another task operates on the
same instance.

See https://bugs.python.org/issue32526.
2019-02-15 16:27:18 -05:00
Tyler Goodlet f44ac4528a Use mem chan in actor core 2019-02-15 16:23:58 -05:00
Tyler Goodlet b42e118e89 Go 3.7 since dataclasses 2019-02-14 13:08:37 -05:00
goodboy 977eaedb0b
Merge pull request #52 from tgoodlet/contexts
Contexts and Pub-Sub
2019-01-25 00:49:07 -05:00
Tyler Goodlet b0b35284f4 Add call/decorate time type checking tests 2019-01-25 00:13:13 -05:00
Tyler Goodlet 3d0de25f93 Do proper `wrapt` arg extraction for type checking
Use an inner function / closure to properly process required arguments
at call time as is recommended in the `wrap` docs. Do async gen and
arg introspection at decorate time and raise appropriate type errors.
2019-01-25 00:10:13 -05:00
Tyler Goodlet 1b405ab4fe s/tickers/topics 2019-01-23 22:35:59 -05:00
Tyler Goodlet 2b1e8773bb Verify subs topics at each step 2019-01-23 22:35:04 -05:00
Tyler Goodlet 7675b01722 Drop py3.6 since we're using @dataclass 2019-01-23 20:02:51 -05:00
Tyler Goodlet 3b19e15306 Don't allow cancelling a cancel_task() task 2019-01-23 20:01:29 -05:00
Tyler Goodlet 855f959768 Don't log traceback on kb interrupt 2019-01-23 20:00:57 -05:00
Tyler Goodlet 9f41297298 Timeout on remote task cancellation
Turns out you get a bad situation if the target actor who's task you're
trying to cancel has already died (eg. from an external
`KeyboardInterrupt` or other error) and so we need to eventually bail on
the RPC request. Also don't bother closing the channel created in
`open_portal()` manually since the cancel scope should take care of all
that.
2019-01-23 19:20:13 -05:00
Tyler Goodlet 226312042a Fix type annots 2019-01-23 00:41:45 -05:00
Tyler Goodlet 36ee6695fb Add initial pubsub test 2019-01-21 12:31:03 -05:00
Tyler Goodlet 1e18c70ad1 Fix func name mismatch 2019-01-21 12:07:58 -05:00
Tyler Goodlet 5e5c917081 Fix run_in_excutor() link 2019-01-21 11:59:44 -05:00
Tyler Goodlet 19349f8cff Add TOC and examples subsections 2019-01-21 11:56:33 -05:00
Tyler Goodlet 276782eb45 Add context examples 2019-01-21 11:50:02 -05:00
Tyler Goodlet b6cc1e8c22 More pub decorator improvements
- when calling the async gen func provided by the user wrap it in
  `@async_generator.aclosing` to ensure correct teardown at cancel time
- expect the gen to yield a dict with topic keys and data values
- add a `packetizer` function argument to the api allowing a user
  to format the data to be published in whatever way desired
- support using the decorator without the parentheses (using default
  arguments)
- use a `wrapt` "adapter" to override the signature presented to the
  `_actor._invoke` inspection machinery
- handle the default case where `tasks` isn't provided; allow only one
  concurrent publisher task
- store task locks in an actor local variable
- add a comprehensive doc string
2019-01-21 09:21:12 -05:00
Tyler Goodlet 97f709cc14 Cancel remote streaming tasks on a local cancel
Use the new `Actor.cancel_task()` api to remotely cancel streaming
tasks spawned by a portal. This guarantees that if an actor is
cancelled all its (remote) portal spawned tasks will be as well.

On portal teardown only cancel all async
generator calls (though we should cancel all RPC requests in general
eventually) and don't close the channel since it may have been passed
in from some other context that wishes to keep it connected. In
`open_portal()` run the message loop shielded so that if the local
task is cancelled, messaging will continue until the internal scope
is cancelled at end of block.
2019-01-21 00:45:54 -05:00