Action with a Y! Why? Cause
async
is in the box.
actyon
offers an approach on a multiplexed flux pattern using coroutines (PEP 492).
pip install actyon
See Documentation
- Github API (Actyon)
- Counter (Flux)
- Traffic Light (State Machine)
- An actyon is defining an isolated execution run.
- Producers are called on all combinations of input dependencies.
- Consumers are called on all results at once.
- Dependencies are available in any kind of structure.
- Dependencies are injected according to function signatures.
- Missing dependencies are ignored, unless no producer can be executed.
- Synchronization points are
- Start
- Conclusion of all producers
- End
- Producers are called asynchronously at once
- Consumers are called asynchronously at once
- Typing is mandatory
- Coroutines for producers and consumers are mandatory
- Python 3.8+ is required
First of all, this is an open source project for everybody to use, distribute, adjust or simply carve out whatever you need. For me it's a case study on dependency injection and coroutines, so don't expect this to be a masterpiece.
Aside from answer N° 1, I want to make clear I'm not a java developer getting started with python. I love python and its capabilities. So making python even greater and more accessible to the people is the key to me. Maybe DI is a step towards that, maybe it's not. Still, this code may provide other developers with an idea to accomplish exactly that.
Once you start developing software, you want it to simplify things. That's the whole definition of a software developer by the way: we are lazy by definition. Anyway, this code shows how you can multiplex tasks and sync them on the interface level. Your tasks are executed asynchronously all together, results are gathered and in the end they are being processed further - again, asynchronously all together. The decorator functionality allows for the application of the SOLID principle, which is pretty neat:
- Single-responsibility principle
- Open–closed principle
- Liskov substitution principle
- Interface segregation principle
- Dependency inversion principle
In this code the bottom two are quite shallow and not really applicable, but let's not get stuck with this. Another key feature of the functional interface is the simplicity. Define an action, use the decorators on whatever functions you have and just execute it. It even got a nice console output when you add hook=actyon.DisplayHook()
to the Actyon
's constructor. Try it out, but caution: parallel actyon execution will break the rendering.