python - How to ensure that script only executes subsequent methods after subprocess.Popen has completed execution -



python - How to ensure that script only executes subsequent methods after subprocess.Popen has completed execution -

i'm running problems here trying utilize subprocess.popen. cannot utilize subprocess.call script i'm writing because i'd able specify environment execution, can in popen through argument method. i've noticed subprocess.popen takes longer finish subprocess.call, , creates problems downstream in script because rest of script relies on exit code (return code) spawned process decide (through set of conditional if statements) on suitable action.

the method involves using subprocess is:

def execute_local(self): ''' spawns test execution process locally , directs standard output , error streams process appropriate log files. ''' self.return_code = subprocess.popen(args = self.cmd_string, stdout = open(self.out_log_filepath, 'w'), stderr = open(self.err_log_filepath, 'w'), shell = true)

i have not yet specified env arguments yet because need create sure works before can move on.

and subsequent method contains conditionals is:

def get_status(self): ''' returns string named either passed or failed itself, depending on exit status of process spawned in execute_local method. of import main.py able examine status of test processes , take appropriate administrative actions either go on new test step or retry give test. ''' print self.return_code if self.return_code == 0: homecoming 'passed' else: homecoming 'failed'

in higher level module, methods called in next order: execute_local ---followed ----> get_status.

previously when did call, execution went smoothly through conditionals, popen, doesn't. when tried debugging print statement print out homecoming code of process spawned subprocess (i added print self.return_code statement @ get_status method can see below), i've observed call, actual see homecoming code, popen, object , memory address.

i appreciate help on this, , if explain me why popen takes much longer run compared call.

thank much!

subprocess.call wrapper around popen waits called process exit. takes same arguments popen , could replace (incorrectly implemented) popen , replace call want.

self.return_code = subprocess.call(args = self.cmd_string, stdout = open(self.out_log_filepath, 'w'), stderr = open(self.err_log_filepath, 'w'), shell = true, env=my_env)

in current implementation, returning popen object, not homecoming code.

python python-2.7 subprocess call popen

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -