def do_process(self): # /##################/# # Check for open # # Check if self.ProcessingActionStr == "open": # import import subprocess if self.ProcessingDirectStr: # /##################/# # Direct case # # popen self.ProcessedPopenVariable = subprocess.Popen( self.ProcessingBashStr.split(" "), shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE ) else: # /##################/# # Indirect case where we build a sh file and put in a text # # Define ProcessedBashPathStr = self.FolderingPathVariable + ProcessFileStr + ".txt" # Check if os.path.isfile(ProcessedBashPathStr): # debug """ self.debug('delete the previous') """ # rm os.popen("rm " + ProcessedBashPathStr) # set self.ProcessedBashStr = 'OUTPUT="$(' + self.ProcessingBashStr + ')"\n' self.ProcessedBashStr += 'echo "${OUTPUT}" > ' + ProcessedBashPathStr # debug """ self.debug( [ 'We write the sh bash script', ('self.',self,['ProcessedBashStr']) ] ) """ # write self.file(ProcessFileStr + ".sh", "w", _WriteVariable=self.ProcessedBashStr).file(_ModeStr="c") # debug """ self.debug( [ 'We call the supprocess', ('self.',self,[ 'FiledPathStr', ]) ] ) """ # kill the previous maybe if self.ProcessedPopenVariable != None: self.ProcessedPopenVariable.kill() # popen self.ProcessedPopenVariable = subprocess.Popen( ["sh", self.FiledPathStr], shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE ) # debug """ self.debug( [ 'We read the output', ] ) """ # wait for connect import time ProcessedReadBool = False ProcessedCountInt = 0 while ProcessedReadBool == False and ProcessedCountInt < 5: try: # read self.ProcessedBashStr = self.file(ProcessFileStr + ".txt", "r").FiledReadVariable # set ProcessedReadBool = True except: # debug """ self.debug( [ 'File read not work' ] ) """ # say that it is not setted ProcessedReadBool = False ProcessedCountInt += 1 time.sleep(0.2) # /##################/# # Check for kill # elif self.ProcessingActionStr == "kill": # kill the process if self.ProcessedPopenVariable != None: # debug """ self.debug('kill the popen variable') """ # kill but before wait a bit to be sure that the db has time to refresh SYS.stdout("Kill the popen variable") SYS.wait(self.ProcessingTimeInt) self.ProcessedPopenVariable.kill() SYS.stdout("It is killed")