pykka
pykka copied to clipboard
Support multiprocessing
multiprocessing
is like threading but a bit slower and allows multiple processors fully.
Has anyone tried this? After a quick glance through the pykka source, and based on what I know about multiprocessing
, it doesn't seem like this should be too difficult. But perhaps there are some issues that aren't immediately apparent.
If you leave out any considerations about having actors running on different executors talking to each other, e.g. a system with only multiprocessing actors, you basically just need:
- something that can run an actor (threads, eventlets),
- something that can be the actor inbox which is safe to use concurrently under the given concurrency model (
queue.Queue
for threads), and - something that can return a single value or exception (often the same type as the actor inbox).
In a "classic" actor model the actors should only be communicating through message passing, so it sounds like multiprocessing
should be easy to implement in principle.
Do you think there are many people sharing state across actors without message passing?
I don't know of that many projects using Pykka, but at least in Mopidy we usually keep quite strictly to the actor rules.
That said, I think that you'll have problems using pykka.ActorRegistry
in a multiprocessing context, since it is simply based on module-level global state, protected by locks.
http://thespianpy.com/doc/
I'd love to see a backend implementation for both multiprocessing and asyncio. The multiprocessing backend should support Process and WorkerPool actors. Sadly I'm too new to Python to give it a serious try, but maybe I will once I've learnt more about the language.