PyPy subprocess

Chris Angelico rosuav at gmail.com
Sun Nov 1 17:11:55 EST 2015


On Mon, Nov 2, 2015 at 8:27 AM, LJ <luisjosenovoa at gmail.com> wrote:
> Im wondering if there is a way in which I can use PyPy to solve the just subproblems in parallel, and return to CPython for the overall routines.
>

You could. What you'd have would be a setup where the subprocess is
utterly independent of the parent; the fact that they both happen to
be written in Python is almost immaterial. Figure out some way of
telling the subprocess what it needs to do (eg command-line parameters
coming through into sys.argv), and getting a response back (eg writing
something to stdout before terminating), and then you can use the
subprocess module to spin off the pypy processes, then (maybe after
doing some other work) wait for each of them to finish.

The subproblem solver could be written in any language at all, here;
there's complete decoupling. If you need to pass a lot of info down
into them, or up and out again, you'll need to serialize it all into
JSON and use stdin/stdout, or something like that. Takes some care,
but it works beautifully... I once had a "Python in Python" setup like
that to make my Python-based web site trigger something in a newer
version of Python than was shipped with my OS (think of a 2.7 invoking
a 3.5 script - I don't remember the actual versions but it was
something like that).

ChrisA



More information about the Python-list mailing list