Skip to content

Factor ActorNursery.run_in_actor() (and possibly Portal.run()) into a new tractor.to_actor wrapper API #477

Description

@goodboy

Originally from the discussion in #287,

Yeah, after spelunking the original design a bit yesterday I think I'm of the opinion that we should at the least decouple .run_in_actor() from the nursery internals and at most possibly deprecate it from the nursery API.

Argument:

  • .run_in_actor() calls can be implemented using .start_actor() + a Portal.run() call spawned from a local trio nursery task

further, a Portal.run() call can be implemented using Portal.open_context() with special handling on child side in the RPC ._invoke() impl; it might actually already be done that way?

-> we can offer a "wrapper" high level API that provides .run_in_actor() as part of a small worker pool API?

I like adopting the parlance from other projects such as .to_thread, to_process, and think we should instead offer a tractor.to_actor. subpkg of APIs which deliver these "higher level one shot" style apis for doing single remote task invocation.

The benefits include:

  • massively simplifying our actor nursery cancellation/spawn machinery

  • moving error collection and propagation up to some local trio task nursery which is not the same nursery responsible for creating subproc management / spawn tasks

yes! this allows us to drop the iface from ActorNursery (and/or possibly Portal? though not sure on this yet) as needed - which would reduce surface area and the current complexity of .run_in_actor() being couple to multiple runtime layers.

  • a simpler API where we can demonstrate how to build the higher level constructs like a worker pool from primitives and there is less ways to do the same thing.

Also linking #172 as maybe another tidbit to consider as sugar level API.


Also see nods in the doc regarding this,
https://goodboy.github.io/tractor/api/core.html#tractor.ActorNursery.run_in_actor

and the original deprecation PR,
#290

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions