AWS Thinkbox Discussion Forums

ProcessUtils.WaitForExit - not waiting?

Hi all, here’s another issue I’m having. When I spawn a process in a post script, I can’t get the script to wait for a return code (The script previously ran fine in deadline 5). Here’s a quick example that I knocked up. I’m running Deadline 6 RC 1 on Windows 7.

# spawnprocess-test.py - run as a post script to a Windows Deadline 6 client

from System.IO import *
from Deadline.Scripting import *
from System.Diagnostics import Process
import tempfile
from time import gmtime, strftime, localtime

def __main__(self):
	
	time = strftime("%a, %d %b %Y %X", localtime())

	print( "\n\n" + time + " Running Post Script: spawnprocess-test.py\n============================\n" )  

	tempFolder = tempfile.gettempdir() 
	testBatFilePath = (tempFolder + "\\tempfile.bat")

	f = open(testBatFilePath,'w')
	f.write("ping 0 -n 30 > nul\necho Finished \nexit")
	f.close()	

	print( "Created " + testBatFilePath )  	

	time = strftime("%a, %d %b %Y %X", localtime())
	print( time + " Spawning process: " + testBatFilePath )  

	process = ProcessUtils.SpawnProcess(testBatFilePath)
	ProcessUtils.WaitForExit( process, -1 )
	returnCode = process.ExitCode
	returnCode = str(returnCode)

	time = strftime("%a, %d %b %Y %X", localtime())
	print (time + " Spawn process returned: " + returnCode); 

The post script successfully runs the automatically created batch file, however it completes (as far as deadline is concerned) straight away, even though the batch file is waiting for 30 seconds.Interestingly, the log does not seem to print the last statement. Any help would be great.

Thanks, Adrian

As i can see you’re using it as a sleep thing. Just a quick question, why don’t you use time.sleep(30) instead? Like that it will surely sleep for 30 seconds without needing to spawn another process so python will surely wait for it to finish :wink:

Thanks for reporting this! This is actually a general bug in the pre/post job script code. We run these scripts in separate threads, and the check we were making to see if the script had finished could return True when it wasn’t actually finished yet.

This will be fixed in RC4.

Cheers,

  • Ryan

Hi bugshunter… This was just an example script. I needed to demonstrate the spawning of an external process that took some time. I’m actually running ffmpeg in my script.

Hi Ryan… Awesome! Thanks!

Privacy | Site terms | Cookie preferences