Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6918

Re: Multiprocessing.connection magic

Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '2.x': 0.05; '3.2': 0.05; 'backwards': 0.07; 'modules.': 0.07; 'python': 0.08; '3.0.': 0.09; 'pm,': 0.10; 'received:209.85.214.174': 0.14; 'received:mail- iw0-f174.google.com': 0.14; 'wrote:': 0.14; 'defined': 0.14; '3.2,': 0.16; 'angelico': 0.16; 'docstring': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'guys,': 0.16; 'objects?': 0.16; 'presumably,': 0.16; 'protocol:': 0.16; 'send()': 0.16; 'stumbled': 0.16; '\xa0what': 0.16; '\xa0while': 0.16; 'compatible': 0.16; 'suggest': 0.19; 'bytes': 0.19; 'header:In-Reply-To:1': 0.21; 'trying': 0.23; 'referring': 0.23; 'fri,': 0.23; 'versions': 0.23; "what's": 0.23; 'function': 0.25; 'object': 0.26; "i'm": 0.27; 'message-id:@mail.gmail.com': 0.28; '"the': 0.28; 'received:209.85.214': 0.28; 'version': 0.29; 'module': 0.30; 'url:library': 0.31; 'skip:\xa0 30': 0.32; 'someone': 0.33; 'to:addr:python-list': 0.33; 'actually': 0.33; 'chris': 0.34; 'that,': 0.34; '2.6': 0.35; '8bit%:3': 0.35; 'explicit': 0.35; 'else': 0.35; 'using': 0.35; 'received:google.com': 0.37; 'received:209.85': 0.37; 'url:docs': 0.37; 'url:python': 0.38; 'could': 0.38; 'url:org': 0.38; 'subject:: ': 0.38; 'some': 0.38; '8bit%:6': 0.39; 'doing': 0.39; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'current': 0.40; 'recommended': 0.40; 'format': 0.40; 'your': 0.60; 'plus': 0.65; 'strange': 0.68; 'reverse': 0.73; 'guaranteed': 0.78; '2.7.1': 0.84; 'possible."': 0.84; 'subject:magic': 0.84; 'subject:skip:M 20': 0.84; '\xa0at': 0.84; '\xa0of': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=VfVf+DvyYfwyBFYw0d2IQnl8L01B8uNQ/keKpl867NA=; b=BV4to/ZJpn8ImsCYy00opum8OKkknouHI+gmrnlynFwYEQUa70LMuQ8EcRQb6kv1CU cBPq4ogyrnfznyj9zeFNnJFcyxrvgFLMonMjZInXVEQYNNeU6WaZm+L+uF10T+M0WEPv hHQL9Fa8bRkZ8TQe7xJhANJkfQBRmynNsrLlY=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=N/DLkOcRgxWxeSsxE7A6T9ja0j8UVKZqpvlEi+5JyWmGFE6kIYkW7Q5xivNgUHqFyy LWdRKQhJK914DuUuOM3yXBWR4It0ZhkA6ZUeaami72swS0W4eSR2lNQij/NBlc+xJoge GpHeLes41LQeWAh8z5TauvXVqJy9P7SnK4MyM=
MIME-Version 1.0
In-Reply-To <171365925.20110603092822@bitdefender.com>
References <171365925.20110603092822@bitdefender.com>
Date Fri, 3 Jun 2011 16:59:20 +1000
Subject Re: Multiprocessing.connection magic
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2418.1307084363.9059.python-list@python.org> (permalink)
Lines 45
NNTP-Posting-Host 82.94.164.166
X-Trace 1307084363 news.xs4all.nl 49048 [::ffff:82.94.164.166]:60316
X-Complaints-To abuse@xs4all.nl
Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.stben.net!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6918

Show key headers only | View raw


On Fri, Jun 3, 2011 at 4:28 PM, Claudiu Popa <cpopa@bitdefender.com> wrote:
> Hello guys,
>      While  working  at a dispatcher using
>  multiprocessing.connection.Listener  module  I've stumbled upon some
>  sort    of  magic  trick  that  amazed  me. How is this possible and
>  what  does  multiprocessing  library doing in background for this to
>  work?

I'm not sure what magic trick you're referring to - is it that you can
use dissimilar versions of Python and send strange objects? I did find
that trying this in reverse (sending from 3.2, receiving with 2.7.1)
failed with "ValueError: unsupported pickle protocol: 3". That, plus
the docstring for send and recv, might suggest what's happening: the
object gets pickled.

Pickling in 2.7.1 (close enough to your 2.6 I presume):
http://docs.python.org/library/pickle.html
Pickling in 3.2:
http://docs.python.org/py3k/library/pickle.html

>From the 3.2 docs:
"The pickle serialization format is guaranteed to be backwards
compatible across Python releases."
"Protocol version 3 was added in Python 3.0. It has explicit support
for bytes and cannot be unpickled by Python 2.x pickle modules. This
is the current recommended protocol, use it whenever it is possible."
"The following types can be pickled:
...
functions defined at the top level of a module
built-in functions defined at the top level of a module
...
"

Presumably, the send() function pickles at the HIGHEST_PROTOCOL or
DEFAULT_PROTOCOL, and recv() unpickles whatever it gets. If you do the
pickling manually, you could choose to use version 2 explicitly, and
then the 2.6 other end could read it comfortably.

I don't know how effective the pickling of functions actually is.
Someone else will doubtless be able to fill that in.

Chris Angelico

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Multiprocessing.connection magic Chris Angelico <rosuav@gmail.com> - 2011-06-03 16:59 +1000
  Re: Multiprocessing.connection magic Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-06-03 10:10 +0200
    Re: Multiprocessing.connection magic Chris Angelico <rosuav@gmail.com> - 2011-06-03 18:36 +1000

csiph-web