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


Groups > comp.lang.python > #7250 > unrolled thread

How to run C++ binaries with python in parallel?

Started byPony <lingyu.ma.fu@googlemail.com>
First post2011-06-08 12:06 -0700
Last post2011-06-08 12:15 -0700
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  How to run C++ binaries with python in parallel? Pony <lingyu.ma.fu@googlemail.com> - 2011-06-08 12:06 -0700
    Re: How to run C++ binaries with python in parallel? Chris Rebert <clp2@rebertia.com> - 2011-06-08 12:15 -0700

#7250 — How to run C++ binaries with python in parallel?

FromPony <lingyu.ma.fu@googlemail.com>
Date2011-06-08 12:06 -0700
SubjectHow to run C++ binaries with python in parallel?
Message-ID<f2a96414-09b0-407f-aaf7-ff62b276734d@d1g2000yqe.googlegroups.com>
Hi all,

I'm a newbie with python, and I have a question about running parallel
C++ binaries with python.

Suppose I have a C++ binary named "test" and it takes two inputs, if I
want to run below three commands in bash:
test a b
test c d
test e f

What's the best way to run it parallel with python?
Can anyone give an example code for doing this?

Is there something similar to OpenMP in C++?

Thanks in advance!

[toc] | [next] | [standalone]


#7251

FromChris Rebert <clp2@rebertia.com>
Date2011-06-08 12:15 -0700
Message-ID<mailman.29.1307560532.11593.python-list@python.org>
In reply to#7250
On Wed, Jun 8, 2011 at 12:06 PM, Pony <lingyu.ma.fu@googlemail.com> wrote:
> Hi all,
>
> I'm a newbie with python, and I have a question about running parallel
> C++ binaries with python.
>
> Suppose I have a C++ binary named "test" and it takes two inputs, if I
> want to run below three commands in bash:
> test a b
> test c d
> test e f
>
> What's the best way to run it parallel with python?

Use the `subprocess` module.

> Can anyone give an example code for doing this?

from subprocess import Popen
cmds = [['test', 'a', 'b'], ['test', 'c', 'd'], ['test', 'e', 'f']]
processes = [Popen(cmd) for cmd in cmds]
for proc in processes:
    proc.wait()

Cheers,
Chris
--
http://rebertia.com

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web