Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'receives': 0.04; 'context': 0.07; 'dynamically': 0.07; 'etc).': 0.09; 'cc:addr :python-list': 0.11; 'python': 0.11; 'def': 0.12; 'thread': 0.14; '12:50': 0.16; '24,': 0.16; 'callable': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'process?': 0.16; 'subject:Pypy': 0.16; 'wrote:': 0.18; 'passing': 0.19; 'feb': 0.22; '>>>': 0.22; 'memory': 0.22; 'example': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'exists': 0.24; 'paul': 0.24; 'cc:2**0': 0.24; 'this:': 0.26; 'pass': 0.26; 'header:In-Reply- To:1': 0.27; 'function': 0.29; 'chris': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'context.': 0.31; 'writes:': 0.31; 'supposed': 0.32; 'another': 0.32; 'actual': 0.34; "can't": 0.35; 'problem.': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'example,': 0.37; 'so,': 0.37; 'skip:o 20': 0.38; 'process,': 0.38; 'pm,': 0.38; 'sure': 0.39; 'tell': 0.60; 'skip:o 30': 0.61; 'soon': 0.63; 'become': 0.64; 'reply': 0.66; 'obvious': 0.74; 'square': 0.74; '2015': 0.84; 'serious.': 0.84; 'mean.': 0.91; 'processes,': 0.91; 'to:none': 0.92; 'state.': 0.95 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=6WsCUwnNtwS6+SAHcrRHl6WDT52qlAjHUNs8sv2fq88=; b=w0VRP9XkEZA+OksxHSnNXa2yRJGP1iIQdU5pYRmOXURYWqQoDnjVl4R0L3OJowQ3il Qd/qEm7XzBunBAMyLnwVR3c5JVozMl/M17c4nJ7//Ci60UUvjtjX+Vkltaf8SYb4l82j Ess/9DbtxauaNp8v7MDfLByRd+ttz/bPtEXSnZ73Hvl16NWS1boqVaDZ2uflnc11GvJJ DBgPoY3qVaKMLfXrQDXwXincDi9jwgMyNWm0ch1Rq26pplpNhsmgejKHr6MjqfbwDiTp c5EOBNLZ2Fk3DjLTr6Stk6O4YIo1R4zUSFv33aOdkIKXqQlE9hzRWeYxqA7EWJD86qho Pbpw== MIME-Version: 1.0 X-Received: by 10.107.160.212 with SMTP id j203mr17937752ioe.43.1424743386135; Mon, 23 Feb 2015 18:03:06 -0800 (PST) In-Reply-To: <871tlgaxi7.fsf@jester.gateway.pace.com> References: <87fv9xdb22.fsf@jester.gateway.pace.com> <54ea7ff4$0$12983$c3e8da3$5496439d@news.astraweb.com> <87zj85bcyu.fsf@jester.gateway.pace.com> <87lhjpb89i.fsf@jester.gateway.pace.com> <87h9udb1eq.fsf@jester.gateway.pace.com> <87bnkkb22u.fsf@jester.gateway.pace.com> <871tlgaxi7.fsf@jester.gateway.pace.com> Date: Tue, 24 Feb 2015 13:03:06 +1100 Subject: Re: Future of Pypy? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424743389 news.xs4all.nl 2862 [2001:888:2000:d::a6]:60088 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86285 On Tue, Feb 24, 2015 at 12:50 PM, Paul Rubin wrote: > Chris Angelico writes: >>> What if you want to dynamically construct a callable and send it to >>> another process? >> I'm not sure what that would actually mean. Do you try to construct it >> out of code that already exists in the other process? Are you passing >> actual code to the other process? > > I gave an example in a reply to Steven, something like > > other_thread_queue.put(lambda x: x*x) > > to tell the other thread it is supposed to square something. It > receives a callable and calls it in its own context. So, you would have to pass code to the other process, probably. What about this: y = 4 other_thread_queue.put(lambda x: x*y) Or this: y = [4] def next_y(): y[0] += 1 return y[0] other_thread_queue.put(next_y) It may not be obvious with your squaring example, but every Python function has its context (module globals, etc). You can't pass a function around without also passing, or sharing, its data. With threads in a single process, this isn't a problem. They all access the same memory space, so they can all share state. As soon as you go to separate processes, these considerations become serious. ChrisA