pykka | 🌀 Pykka makes it easier to build concurrent applications
kandi X-RAY | pykka Summary
kandi X-RAY | pykka Summary
Pykka is a Python implementation of the actor model. The actor model introduces some simple rules to control the sharing of state and cooperation between execution units, which makes it easier to build concurrent applications. For a quickstart guide and a complete API reference, see the documentation.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Run actor loop
- Process a received message
- Unhandled exceptions
- Get attribute by path
- Log the tracebacks
- Joins the given futures
- Define a function to be called when the hook is received
- Ask the actor
- Return True if the actor is alive
- Start the actor loop
- Broadcasts a message to all targets
- Send a message to the actor
- Return the list of actor references that have the given class
- Get actor references by the class name
- Send message to actor
- Run resolvers
- Start the actor
- Resolve an IP address
- Start the actor thread
- Count the number of items in the queue
pykka Key Features
pykka Examples and Code Snippets
struct MyActor
where H: Send + Spawn + Clone + 'static
{
handle: H,
id: String,
}
impl MyActor
where H: Send + Spawn + Clone + 'static
{
pub fn new(h: H) -> MyActor {
MyActor
let system = ThreadPoolExecutor::with_thread_count(2).unwrap();
let handle = system.handle();
let child_spec = ChildSpec::new("worker child".to_owned(),
move |handle| Box::new(MyActor::
Manages everything related to the list of tracks we will play.
See :class:`~mopidy.core.TracklistController`.
Manages playback state and the current playing track.
See :class:`~mopidy.core.PlaybackController`.
Manages the music library, e.g. searchin
import pykka
import asyncio
from flask import Flask
from flask import request
from balebot.handlers import *
from balebot.filters import *
from balebot.models.base_models import Peer
from balebot.models.messages import *
from balebot.upda
Scenario something
Given a running actor system
...
Then it completes successfully
@given('a running actor system')
def step_impl(context):
ActorSystem('simpleSystemBase')
@then('it completes succe
Community Discussions
Trending Discussions on pykka
QUESTION
I'm playing with pykka's actor model, and found some funny behaviour. Here's a demo that
- Launches an actor
- Gets a proxy to it
- Sets one of its @properties
Here's the code:
...ANSWER
Answered 2018-Jul-09 at 08:50Disclaimer: I'm the author of Pykka.
Aside: Pykka isn't dead, it just works quite well for what it was made for: providing an concurrency abstraction for the Mopidy music server and its 100+ extensions.
Pykka's behavior with properties isn't optimal, but there's a reason it is the way it is.
To create a proxy object Pykka must introspect the API of the target object. When testing if the attributes available on the target object are callables, attributes, or "traversible attributes",
getattr()
is called once on each attribute. This causes the property getter to be called. SeeProxy._get_attributes()
andActor._get_attribute_from_path()
for .As there is no way in Python to capture a return value from a property setter, property setting on Pykka proxy takes the safe default of waiting on the setter to complete so that any exceptions raised in the setter can be reraised on the call site in
mainThread()
. The alternative would be to leave any exceptions raised by property setters unhandled. SeeProxy.__setattr__()
for details.
In summary, properties "works" with Pykka, but you get more control by using method calls, as you then always get a future back and can decide yourself if you need to wait for the result or not.
Whether you are using Pykka or not, I find it good practice to not do any expensive work in property getters, but instead use proper methods to do "expensive" work.
API design directly affects how your users will use the API:
- An object with a property invites to repeated use of the same property, and thus repeated recalculation. Keep properties dead simple and cheap.
- An object exposing a method returning a result will usually lead to a caller to keep the result in a variable and reuse the same result instead of calling the method multiple times. Use methods for any non-trivial work. If it is really expensive, consider another prefix than
get_
, for exampleload_
,fetch_
, orcalculate_
, further indicating that the user should keep a handle on the result and reuse it.
To follow up on these principles myself, Mopidy's core API migrated from using lots of properties to using getters and setters a long time ago. In the next major release, all the properties will be removed from Mopidy's core API. Due to the way proxy creation works, this cleanup will reduce the startup time of Mopidy quite a bit.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pykka
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page