本文整理汇总了Python中subprocess.Popen.start方法的典型用法代码示例。如果您正苦于以下问题:Python Popen.start方法的具体用法?Python Popen.start怎么用?Python Popen.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类subprocess.Popen
的用法示例。
在下文中一共展示了Popen.start方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import start [as 别名]
def main():
parser = argparse.ArgumentParser(description="Split aligned reads into chromosomes",formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('input',help="sorted samtools indexed BAM file")
parser.add_argument('-o','--output',help="output directory")
args = parser.parse_args()
m = re.search('([^\/]+)\.bam$',args.input)
if not m:
sys.stderr.write("bam file must end in .bam")
sys.exit()
basename = m.group(1)
args.output = args.output.rstrip('/')
if not os.path.exists(args.output):
os.makedirs(args.output)
cmd = "samtools view -H "+args.input
p = Popen(cmd.split(),stdout=PIPE)
chrs = []
for line in p.stdout:
m = re.match('@SQ\tSN:(\S+)',line)
if not m: continue
chrs.append(m.group(1))
p.communicate()
ps = []
for chr in chrs:
ps.append(Process(target=do_chr,args=(chr,args,basename,)))
ps.append(Process(target=do_un,args=(args,basename,)))
for p in ps: p.start()
for p in ps: p.join()
示例2: MMPSimpleRaytracer
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import start [as 别名]
#.........这里部分代码省略.........
The actual state should not be updated at the end,
as this method could be
called multiple times for the same solution step
until the global convergence
is reached. When global convergence is reached,
finishStep is called and then
the actual state has to be updated.
Solution can be split into individual stages
identified by optional stageID parameter.
In between the stages the additional data exchange can be performed.
See also wait and isSolved services.
:param TimeStep tstep: Solution step
:param int stageID: optional argument identifying
solution stage (default 0)
:param bool runInBackground: optional argument, defualt False.
If True, the solution will run in background (in separate thread
or remotely).
"""
# Check that old simulation is not running:
if not self.isSolved():
return
# Set current tstep
self._curTStep = tstep
# This thread will callback when tracer has ended.
self.postThread = threading.Thread(target=self._runCallback,
args=(self.tracerProcess,
self._tracerProcessEnded))
# Post processing thread will wait for the tracer to finnish
self.postThread.start()
# Wait for process if applicaple
if not runInBackground:
self.wait()
def wait(self):
"""
Wait until solve is completed when executed in background.
"""
print("Waiting...")
self.tracerProcess.wait()
print("Post processing...")
self.postThread.join()
print("Post processing done!")
def isSolved(self):
"""
:return: Returns true or false depending whether solve has completed
when executed in background.
:rtype: bool
"""
if self.tracerProcess.poll() is not None:
return True
if self.postThread.poll() is not None:
return True
return False
def getCriticalTimeStep(self):
"""
:return: Returns the actual (related to current state) critical time
step increment
示例3: MMPRaytracer
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import start [as 别名]
#.........这里部分代码省略.........
# Check that old simulation is not running:
if not self.isSolved():
return
# Check params and fields
initConf.checkRequiredFields(self.fields, FieldID)
initConf.checkRequiredParameters(self.properties, PropertyID)
initConf.checkRequiredFunctions(self.functions, fID=FunctionID)
# Set current tstep and copy previous results as starting values
self._curTStep = tstep
self._copyPreviousSolution()
# Write out JSON file.
self._writeInputJSON(tstep)
# Get mie data from other app
self._getMieData(tstep)
# Start thread to start calculation
self.tracerProcess = Popen( # ["ping", "127.0.0.1", "-n",
# "3", "-w", "10"],
# self.tracerProcess = Popen(["tracer",
# "DefaultLED.json"],
["tracer-no-ray-save", "input.json"],
stdout=PIPE,
stderr=PIPE)
# This thread will callback when tracer has ended.
self.postThread = threading.Thread(target=self._runCallback,
args=(self.tracerProcess,
self._tracerProcessEnded))
# Post processing thread will wait for the tracer to finnish
logger.info('Ray tracing starting...')
self.postThread.start()
# Wait for process if applicaple
if not runInBackground:
self.wait()
def wait(self):
"""
Wait until solve is completed when executed in background.
"""
logger.debug("Tracing...")
self.tracerProcess.wait()
logger.debug("Post processing...")
self.postThread.join()
logger.debug("Post processing done!")
def isSolved(self):
"""
:return: Returns true or false depending whether solve has completed
when executed in background.
:rtype: bool
"""
if self.tracerProcess.poll() is not None:
return True
if self.postThread.poll() is not None:
return True
return False
def getCriticalTimeStep(self):
"""
:return: Returns the actual (related to current state) critical time
step increment
示例4: open
# 需要导入模块: from subprocess import Popen [as 别名]
# 或者: from subprocess.Popen import start [as 别名]
fnull = open(os.devnull,'w')
p = call(cmd,stdout=fnull,shell=True)
fnull.close()
print "** Generating new *.xml files **"
writeToLog(logfile,"** Generating new *.xml files **")
i = 0
# Loop through all inpaths and outfiles
while i <= (len(outfiles)-threadCount):
# Case where full threads are used
threads = threadCount
# Create queue and pool variables
queue0 = manager0.Queue() ; pool = []
for n in range(threads):
p = Process(target=xmlWrite,args=(outfiles_paths[i+n],outfiles[i+n],host_path,cdat_path,start_time,queue0))
p.start() ; pool.append(p)
# Wait for processes to terminate
for p in pool:
p.join()
# Get data back from queue object
inpaths = [] ; outfileNames = [] ; fileZeros = [] ; fileWarnings = [] ; fileNoReads = [] ; fileNoWrites = [] ; fileNones = [] ; errorCodes = [] ; time_since_starts = []
while not queue0.empty():
[inpath,outfileName,fileZero,fileWarning,fileNoRead,fileNoWrite,fileNone,errorCode,time_since_start] = queue0.get_nowait()
inpaths.append(inpath)
outfileNames.append(outfileName)
fileZeros.append(fileZero)
fileWarnings.append(fileWarning)
fileNoReads.append(fileNoRead)
fileNoWrites.append(fileNoWrite)