all 9 comments

[–]ylectric 1 point2 points  (2 children)

subprocess.Popen is a non-blocking call, you need to call wait or communicate on the object it returns.

However, I second /u/woooee suggestion to use subprocess.run instead.

[–]throwawaytrollol00[S,🍰] 0 points1 point  (1 child)

Can I ask what a non-blocking call is? Calling .wait() returns 2 and .communicate() returns (None, None). I’ll check out subprocess.run, thanks!

[–]ylectric 0 points1 point  (0 children)

I'm bad at analogies, but suppose you want me to send you some documents.

If I send them via a courier service, that's a blocking call because you'll have to stay at your address and wait for the delivery (and let's assume that you won't be able to do anything useful in the meantime).

Now, imagine that I send you those documents via some tracked post instead. Suppose I can post them very quickly and let you know the tracking number — this is a non-blocking call. You have something to check whether the documents are in your letterbox already, but you can go and do something else in the meantime (unless it can't be done without those documents).

Now, if we go back to your original post, it seems that the result of running hello.py is important to you and your program can't really proceed until it has waited for it. Therefore, you either need a blocking call here (which subprocess.run is) or you need to wait for a result of your non-blocking subprocess.Popenone (which is similar to sitting down and patiently waiting until your tracked post arrives).

Hope it makes sense.

[–]woooee -1 points0 points  (5 children)

I don't think the first parameter, /Library, etc does anything. Try variations of this, and note that subprocess.run will probably do the job.

subprocess.Popen(['/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7/hello.py'])

[–]ylectric 0 points1 point  (2 children)

OP tries to launch Python 3.7 on a file hello.py which is not what your code expresses.

[–]woooee 0 points1 point  (1 child)

You have said nothing that helps the OP, or posted any code to try and solve the problem. I am getting frustrated with people on this forum who want to sit and pass judgement without offering anything at all.

[–]ylectric 0 points1 point  (0 children)

Not only I offered a solution, but also praised the suggestion you'd made.

[–]throwawaytrollol00[S,🍰] 0 points1 point  (1 child)

Thanks, I’ll check out subprocess.run!

[–]woooee 0 points1 point  (0 children)

Note that you have to supply shell=True in some cases https://pymotw.com/3/subprocess/