本文整理匯總了Python中Utils.ProgressCounter.ProgressCounter.markFinished方法的典型用法代碼示例。如果您正苦於以下問題:Python ProgressCounter.markFinished方法的具體用法?Python ProgressCounter.markFinished怎麽用?Python ProgressCounter.markFinished使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Utils.ProgressCounter.ProgressCounter
的用法示例。
在下文中一共展示了ProgressCounter.markFinished方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: waitForProcess
# 需要導入模塊: from Utils.ProgressCounter import ProgressCounter [as 別名]
# 或者: from Utils.ProgressCounter.ProgressCounter import markFinished [as 別名]
def waitForProcess(process, numCorpusSentences, measureByGap, outputFile, counterName, updateMessage, timeout=None):
"""
Waits for a process to finish, and tracks the number of entities it writes
to it's outputfile. If writing a sentence takes longer than the timeout,
the process is considered stalled and is killed.
"""
maxStartupTime = 600 # Give extra time for the process to start up (even if it creates immediately an empty output file)
counter = ProgressCounter(numCorpusSentences, counterName)
counter.showMilliseconds = True
prevNumSentences = 0 # Number of output sentences on previous check
finalCheckLeft = True # Make one final check to update counters
processStatus = None # When None, process not finished
prevTime = time.time()
startTime = time.time()
# Wait until process is finished and periodically check it's progress.
while processStatus == None or finalCheckLeft:
if processStatus != None: # Extra loop to let counters finish
finalCheckLeft = False # Done only once
if os.path.exists(outputFile[0]): # Output file has already appeared on disk
# Measure number of sentences in output file
numSentences = 0
f = codecs.open(outputFile[0], "rt", **outputFile[1])
for line in f:
if measureByGap:
if line.strip() == "":
numSentences += 1
else:
numSentences += 1
f.close()
# Update status
if numSentences - prevNumSentences != 0: # Process has progressed
counter.update(numSentences - prevNumSentences, updateMessage + ": ")
if finalCheckLeft: # This is a normal loop, not the final check
# Startuptime hasn't yet passed or process has made progress
if time.time() - startTime < maxStartupTime or numSentences - prevNumSentences != 0:
#if prevNumSentences == 0 or numSentences - prevNumSentences != 0:
prevTime = time.time() # reset timeout
else: # Nothing happened on this update, check whether process hung
elapsedTime = time.time() - prevTime
if timeout != None and elapsedTime > timeout:
print >> sys.stderr, "Process timed out (" + str(elapsedTime) + " vs. " + str(timeout) + ")"
print >> sys.stderr, "Killing process"
process.kill()
prevNumSentences = numSentences
time.sleep(1)
else: # Output file doesn't exist yet
prevTime = time.time() # reset counter if output file hasn't been created
processStatus = process.poll() # Get process status, None == still running
counter.markFinished() # If we get this far, don't show the error message even if process didn't finish
return (numSentences, numCorpusSentences)