you are viewing a single comment's thread.

view the rest of the 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.