Future of Pypy?

Chris Angelico rosuav at gmail.com
Mon Feb 23 21:03:06 EST 2015


On Tue, Feb 24, 2015 at 12:50 PM, Paul Rubin <no.email at nospam.invalid> wrote:
> Chris Angelico <rosuav at gmail.com> 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



More information about the Python-list mailing list