<p dir="ltr">On Apr 14, 2013 4:27 PM, "Charles Hixson" <<a href="mailto:charleshixsn@earthlink.net">charleshixsn@earthlink.net</a>> wrote:<br>
><br>
> What is the best approach to implementing actors that accept and post messages (and have no other external contacts).</p>
<p dir="ltr">You might look at how some of the existing Python actor libraries are implemented (perhaps one of these might even save you from reinventing the wheel):</p>
<p dir="ltr"><a href="http://www.pykka.org/en/latest/">http://www.pykka.org/en/latest/</a><br>
<a href="http://www.kamaelia.org/Docs/Axon/Axon.html">http://www.kamaelia.org/Docs/Axon/Axon.html</a><br>
<a href="https://pypi.python.org/pypi/pulsar">https://pypi.python.org/pypi/pulsar</a></p>
<p dir="ltr">Kinda old:<br>
<a href="http://candygram.sourceforge.net/contents.html">http://candygram.sourceforge.net/contents.html</a><br>
<a href="http://osl.cs.uiuc.edu/parley/">http://osl.cs.uiuc.edu/parley/</a></p>
<p dir="ltr">> So far what I've come up with is something like:<br>
> actors     = {}<br>
> mailboxs = {}<br>
><br>
> Stuff actors with actor instances, mailboxes with multiprocessing.queue instances.   (Actors and mailboxes will have identical keys, which are id#, but it's got to be a dict rather than a list, because too many are rolled out to disk.)  And I'm planning of having the actors running simultaneously and continually in a threadpool that just loops through the actors that are assigned to each thread of the pool.<br>

<snip><br>
> It would, however, be better if the mailbox could be specific to the threadpool instance, so less space would be wasted.  Or if the queues could dynamically resize.  Or if there was a threadsafe dict.  Or...  But I don't know that any of these are feasible.  (I mean, yes, I could write all the mail to a database, but is that a better answer, or even a good one?)</p>

<p dir="ltr">My recollection is that the built-in collection types are threadsafe at least to the limited extent that the operations exposed by their APIs (e.g. dict.setdefault) are atomic.<br>
Perhaps someone will be able to chime in with more details.</p>