本文整理匯總了Python中terminal.Terminal.communicate方法的典型用法代碼示例。如果您正苦於以下問題:Python Terminal.communicate方法的具體用法?Python Terminal.communicate怎麽用?Python Terminal.communicate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類terminal.Terminal
的用法示例。
在下文中一共展示了Terminal.communicate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: DADispatcher
# 需要導入模塊: from terminal import Terminal [as 別名]
# 或者: from terminal.Terminal import communicate [as 別名]
#.........這裏部分代碼省略.........
try:
response = request_.recv(1024)
request_.send("OK")
if response == "HB":
self.log("Heart beat from", jobName_)
return
elif response in DADispatcher.STATES:
self.log("Set state", jobName_, response)
else:
raise Exception()
except:
response = "UNKNOWN"
with self._lock:
try:
jobInfo.state = response
finished = False
if jobInfo.state == "DONE":
self._activeJobs[jobInfo.cluster].remove(jobInfo)
finished = True
elif jobInfo.state == "FAILED":
self._activeJobs[jobInfo.cluster].remove(jobInfo)
if self._resubmit:
self._readyJobs[jobInfo.cluster].append(jobInfo)
finished = True
if finished:
if jobInfo.cluster == "interactive":
jobInfo.proc.close()
elif jobInfo.cluster == "local":
jobInfo.proc.communicate()
except:
self.log("Exception while serving", jobName_, "\n", excDump())
if jobInfo.state == "FAILED":
with open(self._workspace + "/logs/" + jobName_ + ".fail", "w") as failLog:
pass
self._stateChanged.set()
def createJob(self, jobName_, cluster_, append=True):
jobInfo = DADispatcher.JobInfo(jobName_)
jobInfo.cluster = cluster_
self._jobInfo[jobName_] = jobInfo
if append:
self._readyJobs[cluster_].append(jobInfo)
if DEBUG:
self.log("Created", jobName_)
return jobInfo
def submitOne(self, cluster, logdir=""):
if len(self._activeJobs[cluster]) >= DADispatcher.MAXACTIVE[cluster] or len(self._readyJobs[cluster]) == 0:
return False
with self._lock:
try:
jobInfo = self._readyJobs[cluster].pop(0)
except IndexError:
return False
if DEBUG:
self.log("submit", jobInfo.name)
示例2: RuntimeError
# 需要導入模塊: from terminal import Terminal [as 別名]
# 或者: from terminal.Terminal import communicate [as 別名]
jobConfig["outputFile"] = options.outputFile.strip()
jobConfig["addSuffix"] = not options.noSuffix
jobConfig["reducer"] = options.reducer.strip()
jobConfig["maxSize"] = options.maxSize
if jobConfig["reducer"] != "None" and not jobConfig["outputFile"]:
raise RuntimeError("Reducer requires output file name specification")
### OPEN WORKSPACE ###
os.mkdir(workspace)
os.mkdir(workspace + "/inputs")
os.mkdir(workspace + "/logs")
if options.environment.strip():
cmds = terminal.communicate(options.environment.strip())
with open(workspace + "/environment", "w") as envFile:
for cmd in cmds:
envFile.write(cmd + "\n")
print "Using {0} as workspace".format(workspace)
### RUNTIME-SPECIFIC CONFIGURATIONS ###
jobConfig["taskID"] = taskID
jobConfig["serverHost"] = os.environ["HOSTNAME"]
jobConfig["serverPort"] = tcpServer.server_address[1]
jobConfig["serverWorkDir"] = TMPDIR + "/" + taskID
jobConfig["logDir"] = HTMLDIR + "/" + taskID + "/logs"
# In principle log directory can be anywhere; we are choosing it to be directly in the HTMLDIR for convenience