def parent_processing(self,fd): global cid global DONE_HASH #print self.ident if self.time_handling: self.spawn_timer() if self.build != '' : self.conf['command'] = 'SANDBOX='+self.build+'/sandbox; BUILD_IDENTIFIER='+self.BUILD_IDENTIFIER+' ; '+self.conf['command'] #Kedar #cid.append(self.pid) #appending the child process id for safe clean-up if self.allIsWell: self.write(fd,'cd '+ self.conf['path']) self.readtillexpect(fd,self.EXPECT) #If there is issue in the expect ,where the second time read directly results in the expect which is a bogus one bcoz of the previous command to change the path, simple fix would be to do a read by select method for a period of time so the fd is emptied. #self.backup_read(fd) unblocked_read(fd,1024,3) self.write(fd,self.conf['command']) if int(self.port) > 0 : self.port_monitor() else: JOB_HASH[self.JOB_ID] = True #this should have been under else statement #self.unblocking_read3(fd,output,data) self.readtillexpect(fd,self.EXPECT,True) self.process_killed = True cid.remove(self.path) #cid.pop() JOB_HASH[self.JOB_ID] = False #print 'a value popped',self.path DONE_HASH[self.JOB_ID] = True
def readtillexpect(self,fd,expect,log=False): ''' the key method that reads till the Job is done''' global done,kill,KILL_DICT assert isinstance(expect,str) try: fi = self.openlog(self.log,'w',1024,log) reply = '' self.restarted_times = 0 has_restarted = False self.file_size = 0 max_kill_attempts = 20 kill_attempts = 0 self.max_file_size = 100**4 while True: if has_restarted: self.write(fd,self.conf['command']) reply = '' has_restarted = False self.log = self.log+'.'+str(self.restarted_times) fi = self.openlog(self.log,'w',1024,log) if kill or KILL_DICT[self.path] or (self.is_slave and (not self.SEQ) and not JOB_HASH[self.MASTER_ID]): #can be argued to be wrong implementation but logically correct as it is used in logical and only if it is a slave the second part i.e., JOB_HASH[self.master_id] is checked #print 'got a kill signal' print 'I reached here ', self.SEQ,' ',self.path self.write(fd,'\x03') time.sleep(4) kill_attempts += 1 #print 'no of attempts :',kill_attempts if kill_attempts > max_kill_attempts: print 'reached the point of hard kill' self.hard_kill(fd,fi,log) rd,wt,ex = select.select([fd],[],[],.1) if fd in rd: rep = os.read(fd,1024) rep.replace('\r','') #print rep, self.writelog(fi,rep,log) if log and self.file_size > self.max_file_size: fi = self.file_ops(fi) reply += rep self.file_size += len(rep) if re.search(expect,reply) :#or kill_attempts > max_kill_attempts: #rep = self.backup_read(fd) # A rather more cautious read to make sure the buffer is cleared up rep = unblocked_read(fd,1024,3) self.writelog(fi,rep,log) kill_attempts = 0 if self.restart(log): has_restarted = True continue break finally: self.closelog(fi)