- Timestamp:
- Jan 9, 2017 11:07:28 AM (8 years ago)
- Location:
- trunk/src/VBox/ValidationKit
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/common/utils.py
r65007 r65196 435 435 return None; 436 436 437 def processPopenSafe(*aPositionalArgs, **dKeywordArgs): 438 """ 439 Wrapper for subprocess.Popen that's Ctrl-C safe on windows. 440 """ 441 if getHostOs() == 'win': 442 if dKeywordArgs.get('creationflags', 0) == 0: 443 dKeywordArgs['creationflags'] = subprocess.CREATE_NEW_PROCESS_GROUP; 444 return subprocess.Popen(*aPositionalArgs, **dKeywordArgs); 445 437 446 def processCall(*aPositionalArgs, **dKeywordArgs): 438 447 """ 439 Wrapper around subprocess.call to deal with its absen se in older448 Wrapper around subprocess.call to deal with its absence in older 440 449 python versions. 441 450 Returns process exit code (see subprocess.poll). … … 444 453 assert dKeywordArgs.get('stderr') is None; 445 454 _processFixPythonInterpreter(aPositionalArgs, dKeywordArgs); 446 oProcess = subprocess.Popen(*aPositionalArgs, **dKeywordArgs);455 oProcess = processPopenSafe(*aPositionalArgs, **dKeywordArgs); 447 456 return oProcess.wait(); 448 457 … … 453 462 """ 454 463 _processFixPythonInterpreter(aPositionalArgs, dKeywordArgs); 455 oProcess = subprocess.Popen(stdout=subprocess.PIPE, *aPositionalArgs, **dKeywordArgs);464 oProcess = processPopenSafe(stdout=subprocess.PIPE, *aPositionalArgs, **dKeywordArgs); 456 465 457 466 sOutput, _ = oProcess.communicate(); … … 541 550 def sudoProcessPopen(*aPositionalArgs, **dKeywordArgs): 542 551 """ 543 sudo (or similar) + subprocess.Popen.552 sudo (or similar) + processPopenSafe. 544 553 """ 545 554 _processFixPythonInterpreter(aPositionalArgs, dKeywordArgs); 546 555 _sudoFixArguments(aPositionalArgs, dKeywordArgs); 547 return subprocess.Popen(*aPositionalArgs, **dKeywordArgs);556 return processPopenSafe(*aPositionalArgs, **dKeywordArgs); 548 557 549 558 -
trunk/src/VBox/ValidationKit/testboxscript/testboxscript.py
r62484 r65196 33 33 __version__ = "$Revision$" 34 34 35 import subprocess 36 import sys 37 import os 38 import time 35 import platform; 36 import subprocess; 37 import sys; 38 import os; 39 import time; 39 40 40 41 … … 42 43 # @remarks These will _never_ change 43 44 # @{ 44 TBS_EXITCODE_FAILURE = 1 45 TBS_EXITCODE_SYNTAX = 2 46 TBS_EXITCODE_NEED_UPGRADE = 9 45 TBS_EXITCODE_FAILURE = 1; # RTEXITCODE_FAILURE 46 TBS_EXITCODE_SYNTAX = 2; # RTEXITCODE_SYNTAX 47 TBS_EXITCODE_NEED_UPGRADE = 9; 47 48 ## @} 48 49 … … 59 60 Init 60 61 """ 61 self. task = None62 self.oTask = None 62 63 63 64 def __del__(self): … … 65 66 Cleanup 66 67 """ 67 if self. task is not None:68 if self.oTask is not None: 68 69 print 'Wait for child task...' 69 self. task.terminate()70 self. task.wait()70 self.oTask.terminate() 71 self.oTask.wait() 71 72 print 'done. Exiting' 72 self. task = None;73 self.oTask = None; 73 74 74 75 def run(self): … … 107 108 rcExit = TBS_EXITCODE_FAILURE; 108 109 while True: 109 self.task = subprocess.Popen(asArgs, shell=False); 110 rcExit = self.task.wait(); 111 self.task = None; 110 self.oTask = subprocess.Popen(asArgs, 111 shell = False, 112 creationflags = (0 if platform.system() != 'Windows' 113 else subprocess.CREATE_NEW_PROCESS_GROUP)); # for Ctrl-C isolation 114 rcExit = self.oTask.wait(); 115 self.oTask = None; 112 116 if rcExit == TBS_EXITCODE_SYNTAX: 113 117 break; -
trunk/src/VBox/ValidationKit/testboxscript/testboxtasks.py
r62484 r65196 423 423 # Spawn child. 424 424 try: 425 oChild = subprocess.Popen(asArgs,426 shell = False,427 bufsize = -1,428 stdout = subprocess.PIPE,429 stderr = subprocess.STDOUT,430 cwd = self._oTestBoxScript.getPathSpill(),431 universal_newlines = True,432 close_fds = (False if utils.getHostOs() == 'win' else True),433 preexec_fn = (None if utils.getHostOs() in ['win', 'os2']434 else os.setsid)); # pylint: disable=E1101425 oChild = utils.processPopenSafe(asArgs, 426 shell = False, 427 bufsize = -1, 428 stdout = subprocess.PIPE, 429 stderr = subprocess.STDOUT, 430 cwd = self._oTestBoxScript.getPathSpill(), 431 universal_newlines = True, 432 close_fds = (False if utils.getHostOs() == 'win' else True), 433 preexec_fn = (None if utils.getHostOs() in ['win', 'os2'] 434 else os.setsid)); # pylint: disable=E1101 435 435 except Exception, oXcpt: 436 436 self._log('Error creating child process %s: %s' % (asArgs, oXcpt)); -
trunk/src/VBox/ValidationKit/tests/unittests/tdUnitTest1.py
r62484 r65196 633 633 oChild = utils.sudoProcessPopen(asArgs, stdin = oDevNull, stdout = sys.stdout, stderr = sys.stdout); 634 634 else: 635 oChild = subprocess.Popen(asArgs, stdin = oDevNull, stdout = sys.stdout, stderr = sys.stdout);635 oChild = utils.processPopenSafe(asArgs, stdin = oDevNull, stdout = sys.stdout, stderr = sys.stdout); 636 636 except: 637 637 if sName in [ 'tstAsmStructsRC', # 32-bit, may fail to start on 64-bit linux. Just ignore.
Note:
See TracChangeset
for help on using the changeset viewer.