Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; 'url:sourceforge': 0.03; 'dynamically': 0.07; 'extent': 0.07; 'apis': 0.09; 'chime': 0.09; 'feasible.': 0.09; 'instances.': 0.09; 'keys,': 0.09; 'subject:design': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'thread': 0.14; 'actors': 0.16; 'dict': 0.16; 'instances,': 0.16; 'loops': 0.16; 'mean,': 0.16; 'subject:item': 0.16; 'url:kamaelia': 0.16; 'wrote:': 0.18; 'implementing': 0.19; 'cc:addr:python.org': 0.22; 'instance,': 0.24; 'subject:problem': 0.24; 'cc:2**0': 0.24; "i've": 0.25; '>': 0.26; 'post': 0.26; 'least': 0.26; 'url:edu': 0.26; 'header:In-Reply-To:1': 0.27; 'external': 0.29; 'database,': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(perhaps': 0.31; 'continually': 0.31; 'libraries': 0.31; 'stuff': 0.32; 'url:python': 0.33; 'running': 0.33; '(e.g.': 0.33; 'implemented': 0.33; 'could': 0.34; 'something': 0.35; 'operations': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; '14,': 0.36; 'url:org': 0.36; 'too': 0.37; 'skip:& 10': 0.38; 'list,': 0.38; 'planning': 0.38; 'pm,': 0.38; 'rather': 0.38; 'space': 0.40; 'how': 0.40; 'even': 0.60; 'details.': 0.61; 'save': 0.62; 'more': 0.64; 'mailbox': 0.68; 'dict.': 0.84; 'or...': 0.84; 'sender:addr:chris': 0.84; 'url:contents': 0.84; 'url:latest': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=Guj85LUL7LgfQ31H4NT3Tp/NahiOM+ZAQVyk7VQpuwo=; b=axkJLrTw2K9tmRu4tTomK9Ab8MYcT3XD5J2Mmc5o7HV+LceeEw22aKrz4yMCIPcjCD zS6T0KSpHBZ8Qb7e2rit/tAHSfUALjJPwHHo/6e89MRYE+jd+uNkZVSrz4P02kbKbEfo TpagwgwxDh+UHyY5Ao3DJt9+v/3EPj6HmzV9I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :x-gm-message-state; bh=Guj85LUL7LgfQ31H4NT3Tp/NahiOM+ZAQVyk7VQpuwo=; b=ikfJCwi/r9DtGL64jndIqHlHaBq3JB7PAhgZ1vfyLbXOhwFAbwv9lOWppGP6LQNa3s k74ZkugoqNQu3JvJbHS89z5MlIrLfZAB1oj4CUixdvBESaSaTdaFWm9R++jwvoyn2nqE Lq5d8uA2JK+ao3C5++lzpm8bKsBaqfKinV4H7bIa7gR2z8xejZmdcb/btcvmo9yWHD66 w2rkIo3XLyd+jQp9r0WgQmMldGRMWX8iGindGBAKv7F3dMHOBr+d+E1VDYKa/dPQp4Jv JhVIH1s4rM3VtW/CVyayHCl3/+PefNmXTLe/PWEuUU4PBHdbfHjb+8GaM3ic7dCAQPpJ CAqA== MIME-Version: 1.0 X-Received: by 10.50.53.176 with SMTP id c16mr4174513igp.36.1365993174919; Sun, 14 Apr 2013 19:32:54 -0700 (PDT) Sender: chris@rebertia.com In-Reply-To: <516B37CB.1020607@earthlink.net> References: <516B37CB.1020607@earthlink.net> Date: Sun, 14 Apr 2013 19:32:54 -0700 X-Google-Sender-Auth: d4l5WVZuaVaOF-tZkkFpRXfRowk Subject: Re: Threadpool item mailboxes design problem From: Chris Rebert To: Charles Hixson Content-Type: multipart/alternative; boundary=f46d04339ca801deb304da5d12c8 X-Gm-Message-State: ALoCoQkGeEtDGZ+qfkC23k4OfcWAvYbReLyp38BmpKifh/SVVof4c9m7h0uxviIvHFjpbsmWeEKG Cc: Python X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 93 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1365993185 news.xs4all.nl 2656 [2001:888:2000:d::a6]:48128 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43596 --f46d04339ca801deb304da5d12c8 Content-Type: text/plain; charset=UTF-8 On Apr 14, 2013 4:27 PM, "Charles Hixson" wrote: > > What is the best approach to implementing actors that accept and post messages (and have no other external contacts). 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): http://www.pykka.org/en/latest/ http://www.kamaelia.org/Docs/Axon/Axon.html https://pypi.python.org/pypi/pulsar Kinda old: http://candygram.sourceforge.net/contents.html http://osl.cs.uiuc.edu/parley/ > So far what I've come up with is something like: > actors = {} > mailboxs = {} > > 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. > 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?) 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. Perhaps someone will be able to chime in with more details. --f46d04339ca801deb304da5d12c8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable

On Apr 14, 2013 4:27 PM, "Charles Hixson" <charleshixsn@earthlink.net>= ; wrote:
>
> What is the best approach to implementing actors that accept and post = messages (and have no other external contacts).

You might look at how some of the existing Python actor libr= aries are implemented (perhaps one of these might even save you from reinve= nting the wheel):

http://www.pykka= .org/en/latest/
http://www.kamaelia= .org/Docs/Axon/Axon.html
https://pypi.python.org/pyp= i/pulsar

Kinda old:
http://candygram= .sourceforge.net/contents.html
http://osl.cs.uiuc.edu/parley/

> So far what I've come up with is something like: > actors =C2=A0 =C2=A0 =3D {}
> mailboxs =3D {}
>
> Stuff actors with actor instances, mailboxes with multiprocessing.queu= e instances. =C2=A0 (Actors and mailboxes will have identical keys, which a= re id#, but it's got to be a dict rather than a list, because too many = are rolled out to disk.) =C2=A0And I'm planning of having the actors ru= nning simultaneously and continually in a threadpool that just loops throug= h the actors that are assigned to each thread of the pool.
<snip>
> It would, however, be better if the mailbox could be specific to the t= hreadpool instance, so less space would be wasted. =C2=A0Or if the queues c= ould dynamically resize. =C2=A0Or if there was a threadsafe dict. =C2=A0Or.= .. =C2=A0But I don't know that any of these are feasible. =C2=A0(I mean= , yes, I could write all the mail to a database, but is that a better answe= r, or even a good one?)

My recollection is that the built-in collection types are th= readsafe at least to the limited extent that the operations exposed by thei= r APIs (e.g. dict.setdefault) are atomic.
Perhaps someone will be able to chime in with more details.

--f46d04339ca801deb304da5d12c8--