def child(): print 'Starting child' currentProc = GetCurrentProcess() injob = IsProcessInJob(currentProc) print "Is in a job?: %s" % injob can_create = CanCreateJobObject() print 'Can create job?: %s' % can_create process = Popen('c:\\windows\\notepad.exe') assert process._job jobinfo = QueryInformationJobObject(process._job, 'JobObjectExtendedLimitInformation') print 'Job info: %s' % jobinfo limitflags = jobinfo['BasicLimitInformation']['LimitFlags'] print 'LimitFlags: %s' % limitflags process.kill()
def child(): print "Starting child" currentProc = GetCurrentProcess() injob = IsProcessInJob(currentProc) print "Is in a job?: %s" % injob can_create = CanCreateJobObject() print "Can create job?: %s" % can_create process = Popen("c:\\windows\\notepad.exe") assert process._job jobinfo = QueryInformationJobObject(process._job, "JobObjectExtendedLimitInformation") print "Job info: %s" % jobinfo limitflags = jobinfo["BasicLimitInformation"]["LimitFlags"] print "LimitFlags: %s" % limitflags process.kill()
def parent(): print 'Starting parent' currentProc = GetCurrentProcess() if IsProcessInJob(currentProc): print >> sys.stderr, "You should not be in a job object to test" sys.exit(1) assert CanCreateJobObject() print 'File: %s' % __file__ command = [sys.executable, __file__, '-child'] print 'Running command: %s' % command process = Popen(command) process.kill() code = process.returncode print 'Child code: %s' % code assert code == 127
def run_pipe(self, cmd): if self.debug: print('cmd: %s' % cmd) try: p = Popen((cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output = p.stdout.readlines() err = p.stderr.readlines() starttime=time() exitCode = p.wait(self.testTimeOut) #abort if it takes longer than 60 seconds if exitCode < 0 and self.testTimeOut>-1 and time()-starttime>self.testTimeOut: # process timed out return 'timedOut' return (output,err,exitCode) except KeyboardInterrupt: print '\n\nKeyboardInterrupt detected ... killing process' p.kill() self.killmyself()