Skip to content
Advertisement

python: subprocess returns nothing when running scripts which take longer time

Beginner here with subrpocess problem:

The below line works fine when I run both the scripts with less data which takes around 10-20minutes, however with bigger data to be processed the subprocess returns nothing once both the scripts are completed (lets say in an hour).

Also: Often with lesser data, it behaves abnormally as well i.e. not returning the status_code/going through. I then have to just run the snippet again and it works. Any solid reasoning would help alot!

JavaScript

I fail to understand why that happens (or should I use a different approach?), Any help would be very much appreciated. Thank you!

Sample of scripts (both scriptA and scriptB):

JavaScript

Also, no scriptA or scriptB has anywhere sys.exit()

EDIT:

Screenshot:

tried printig the status_code before the if condition, nothing was printed and in the terminal, I see a cursor just blinking.

enter image description here

Also (looking for any python processes): using ps -ax | grep python shows no relevant information (Picture attached)

enter image description here

Advertisement

Answer

Try running your processes separately to get a better idea where the failure is occurring

JavaScript

The above uses a list to hold the running processes so you can process them in a loop and avoid repetitive code. If you will definitely only have two subprocesses you could choose not to use the loop.

JavaScript

notice that Popen requires a list of arguments and won’t accept a single string, but I’ve used shlex.split in this example to allow use of a single string for the command and achieve the same result.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement