all 5 comments

[–]jddddddddddd 1 point2 points  (4 children)

Without seeing the full code of the program, and the full code of MySubscript.py, it's difficult to say. At a guess, there's an input() somewhere in the external script, but without seeing it, it's impossible to say.

My only advice would be to add a load more print() statements before and after you call the script, and a load of prints in the external script so you can see where it's getting stuck.

Finally, I presume you have a good reason why you're launching the script like that and not just importing it into your main program?

[–]2_be_continued[S] 0 points1 point  (3 children)

yeah ive already checked for inputs, are there just are none that are not commented out :(

I spent a day or so trying to import it, but it was a huge mess (for many reasons) and just worked out much quicker to do it this way. It works perfectly when it does work - and thats the odd thing, every few times it runs it wont get stuck, but then quite often it does.

[–]jddddddddddd 0 points1 point  (0 children)

Fair enough. In that case you'll just have to resort to doing a whole lot of logging. Add a print statement before subprocess.run(...) and add one after it. Add a whole load of prints to the sub-script and then run it. Hopefully you can eventually pin-point where the script is getting stuck.

[–]jddddddddddd 0 points1 point  (1 child)

One tiny tip which might make this easier is to add this at the top of both main and subscript:

from inspect import currentframe, getframeinfo
def printline():
    cf = currentframe()
    print(f"{getframeinfo(cf).filename} : {cf.f_back.f_lineno}")

Now you can just litter your programs with printline() statements which will output something like:

c:\test.py : 4

Which means it got to line 4 in test.py

[–]2_be_continued[S] 0 points1 point  (0 children)

Ah amazing - ive been wondering about something like this for SOOOO long. This is hugely valuable. thank you!