Sam
Sam

Reputation: 323

Make Python wait for commands to end

I have a python program which dynamically move and rename files into a hadoop cluster. The files usually range from 10mb(parsed) up to 1.5gb (raw data). For the move commands to finish it can take a while and from what I can tell python races through them and none of the move commands get to finish. What is the proper way to have python wait for previous commands. I store the commands in a variable and pass it to os.system. The relevant code is

os.system(moverawfile)
os.system(renamerawfile)
os.system(moveparsedfile)
os.system(renameparsedfile)

I know rename commands are done basically instantaneously. Am I not supposed to use os.system? How do i ensure that python will wait for each command to finish before moving onto the next one.

Upvotes: 0

Views: 1067

Answers (1)

Bob Ezuba
Bob Ezuba

Reputation: 510

I would suggest that you use run from subprocess as per Python documentation. It waits for your command to complete before returning.

Upvotes: 1

Related Questions