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

P

Pony

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!
 
C

Chris Rebert

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top