0

I need to run different *.exe files in parallel in python 2.7. These *.exe files were created using the C++ language. Also, I need that the cmd window opens for each *.exe file called.

I've already tried something of multiprocessing library, but it didn't work. Anything happened and the PC crashed...

import os
import subprocess

cwd = os.getcwd()

cmd_MakeBackgroundImage = cwd+"\\MakeBackgroundImage.exe"
cmd_SFVTest = cwd + "\\SFVTest.exe"
cmd_Wavelet_x = cwd + "\\Wavelet_x.exe"
cmd_Dataform_x = cwd + "\\Dataform_x.exe"
cmd_Wavelet_y = cwd + "\\Wavelet_y.exe"
cmd_Dataform_y = cwd + "\\Dataform_y.exe"

process_1 = os.system(cmd_MakeBackgroundImage)

process_2 = os.system(cmd_SFVTest)

#I need to run "cmd_Wavelet_x" at the same time of "cmd_Wavelet_y"
#So I need to parallelize process_3 and process_4
process_3 = os.system(cmd_Wavelet_x)

process_4 = os.system(cmd_Wavelet_y)

#I need to run "cmd_Dataform_x" at the same time of "cmd_Dataform_y"
#So I need to parallelize process_5 and process_6
process_5 = os.system(cmd_Dataform_x)

process_6 = os.system(cmd_Dataform_y)

I have an intermediate knowledge of python and I don't know anything about parallelization in Python.

The code that I described does exactly that I need but in a sequential way. The parallelization that I described will decrease the code runtime in about 1h.

It is very important that the cmd window opens for each *.exe, because these cmd windows indicate the status of the code running...

Thank You!

1 Answer 1

2

Update<\b>: In Python 2.7, you can do:

pip install futures

to get all the features in concurrent.futures

Still using Python 2.7? DoD is 2020. If you move to 3.2+ you can easily use concurrent.futures with almost the same code.

import concurrent.futures
import os

cwd = os.getcwd()

cmd_MakeBackgroundImage = cwd+"\\MakeBackgroundImage.exe"
cmd_SFVTest = cwd + "\\SFVTest.exe"
cmd_Wavelet_x = cwd + "\\Wavelet_x.exe"
cmd_Dataform_x = cwd + "\\Dataform_x.exe"
cmd_Wavelet_y = cwd + "\\Wavelet_y.exe"
cmd_Dataform_y = cwd + "\\Dataform_y.exe"

# add cmds to be ran concurrently
programs = [cmd_SFVTest, cmd_Wavelet_x, cmd_Dataform_x, cmd_Wavelet_y, cmd_Dataform_y]

# you can use either Process or Thread depends on your needs

with concurrent.futures.ProcessPoolExecutor() as executor:
    executor.map(os.system, programs)

Hope this helps

Sign up to request clarification or add additional context in comments.

1 Comment

Hi it works fine. However I need to run MakeBackgroundImage.exe and SFVTest.exe using os.system before the other codes. When I use concurrent.futures after os.system all the exe files previously executed are executed again in parallel. It is a strange bug. I am using Spyder 3.3.6.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.