1

In linux, I have a executable, that should be run like this: ./a.exe inputdata

I want to launch this executable in my python script, but I do not want to block the rest of the python code.

I tried soemthing like this, but

# launch sensor node
def launchA():
    subprocess.Popen(["Path/a.exe", inputdata])

if __name__ == '__main__':
    p = multiprocessing.Process(target=launchA,args=())
    p.start()
    print("sensorlaunched")

However, the luanchA process still blocks the print function.

What went wrong in my code? Thanks!

1
  • 2
    You've used the .exe extension on a Linux binary? That's heresy! Commented Feb 29, 2012 at 16:55

1 Answer 1

3

What you're doing is pure overkill: you're creating a process with multiprocessing to manage a process created with subprocess. Just use subprocess alone:

p = subprocess.Popen(["Path/a.exe", inputdata])

Now p is a handle referring to the running a.exe process and your script can continue doing what it was doing.

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

5 Comments

I just tired "p = subprocess.Popen(["Path/a.exe", inputdata])", but it still blocks the print function... The a.exe grabs the terminal, and I do not see print("hello") function is exectuted...
@XingFan: a.exe and the original process write to the same terminal, but no process "grabs" it. Having two simultaneously running processes writing to the same terminal will certainly mix the two data streams in a non-deterministic way, but that does mean the original process blocks.
I c. Thanks! But I tried to add "&" in the command,like this p = subprocess.Popen(["Path/a.exe", inputdata],"&") to release the terminal, but I still do not see the print function is executed.........
@XingFan: that & doesn't do anything. The fact that nothing changes means the issue is not with subprocess.
@XingFan: There is no such thing as "releasing the terminal". The terminal isn't owned by any process. And adding a random "&" as parameter to Popen() will lead to an error.

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.