本文整理汇总了Python中Qtrac类的典型用法代码示例。如果您正苦于以下问题:Python Qtrac类的具体用法?Python Qtrac怎么用?Python Qtrac使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Qtrac类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scale
def scale(size, smooth, source, target, concurrency):
canceled = False
jobs = multiprocessing.JoinableQueue()
results = multiprocessing.Queue()
create_processes(size, smooth, jobs, results, concurrency)
todo = add_jobs(source, target, jobs)
try:
jobs.join()
except KeyboardInterrupt: # May not work on Windows
Qtrac.report("canceling...")
canceled = True
copied = scaled = 0
while not results.empty(): # Safe because all jobs have finished
result = results.get_nowait()
copied += result.copied
scaled += result.scaled
return Summary(todo, copied, scaled, canceled)
示例2: results
def results():
while True:
result = (yield)
results.todo += result.todo
results.copied += result.copied
results.scaled += result.scaled
Qtrac.report("{} {}".format("copied" if result.copied else "scaled",
os.path.basename(result.name)))
示例3: main
def main():
limit, concurrency = handle_commandline()
Qtrac.report("starting...")
filename = os.path.join(os.path.dirname(__file__), "whatsnew.dat")
jobs = multiprocessing.JoinableQueue()
results = multiprocessing.Queue()
create_processes(limit, jobs, results, concurrency)
todo = add_jobs(filename, jobs)
process(todo, jobs, results, concurrency)
示例4: main
def main():
size, smooth, source, target, concurrency = handle_commandline()
Qtrac.report("starting...")
canceled = False
try:
scale(size, smooth, source, target, concurrency)
except KeyboardInterrupt:
Qtrac.report("canceling...")
canceled = True
summarize(concurrency, canceled)
示例5: summarize
def summarize(summary):
message = "copied {} scaled {} ".format(summary.copied, summary.scaled)
difference = summary.todo - (summary.copied + summary.scaled)
if difference:
message += "skipped {} ".format(difference)
message += "single-threaded"
if summary.canceled:
message += " [canceled]"
Qtrac.report(message)
print()
示例6: summarize
def summarize(summary, concurrency):
message = "copied {} scaled {} ".format(summary.copied, summary.scaled)
difference = summary.todo - (summary.copied + summary.scaled)
if difference:
message += "skipped {} ".format(difference)
message += "using {} processes".format(concurrency)
if summary.canceled:
message += " [canceled]"
Qtrac.report(message)
print()
示例7: main
def main():
limit, how_many_threads = handle_commandline()
Qtrac.report("starting...")
filename = os.path.join(os.path.dirname(__file__), "whatsnew.dat")
jobs = queue.Queue()
results = queue.Queue()
create_threads(limit, jobs, results, how_many_threads)
todo = add_jobs(filename, jobs)
process(todo, jobs, results, how_many_threads)
示例8: summarize
def summarize(concurrency, canceled):
message = "copied {} scaled {} ".format(results.copied, results.scaled)
difference = results.todo - (results.copied + results.scaled)
if difference:
message += "skipped {} ".format(difference)
message += "using {} coroutines".format(concurrency)
if canceled:
message += " [canceled]"
Qtrac.report(message)
print()
示例9: scaler
def scaler(receiver, sink, size, smooth, me):
while True:
sourceImage, targetImage, who = (yield)
if who == me:
try:
result = scale_one(size, smooth, sourceImage, targetImage)
sink.send(result)
except Image.Error as err:
Qtrac.report(str(err), True)
elif receiver is not None:
receiver.send((sourceImage, targetImage, who))
示例10: worker
def worker(limit, jobs, results):
while True:
try:
feed = jobs.get()
ok, result = Feed.read(feed, limit)
if not ok:
Qtrac.report(result, True)
elif result is not None:
Qtrac.report("read {}".format(result[0][4:-6]))
results.put(result)
finally:
jobs.task_done()
示例11: reader
def reader(receiver, sink, limit, me):
while True:
feed, who = (yield)
if who == me:
ok, result = Feed.read(feed, limit)
if not ok:
Qtrac.report(result, True)
result = None
else:
Qtrac.report("read {} at {}".format(feed.title, feed.url))
sink.send(result)
elif receiver is not None:
receiver.send((feed, who))
示例12: worker
def worker(size, smooth, jobs, results):
while True:
try:
sourceImage, targetImage = jobs.get()
try:
result = scale_one(size, smooth, sourceImage, targetImage)
Qtrac.report("{} {}".format("copied" if result.copied else
"scaled", os.path.basename(result.name)))
results.put(result)
except Image.Error as err:
Qtrac.report(str(err), True)
finally:
jobs.task_done()
示例13: main
def main():
t1 = time.time()
print(multiprocessing.cpu_count())
size, smooth, source, target, concurrency = (100,1,".",".",4) #handle_commandline()
Qtrac.report("starting...")
summary = scale(size, smooth, source, target, concurrency)
v = time.time() - t1
print("=="*20)
print "time:%s" %(v)
示例14: process
def process(todo, jobs, results, concurrency):
canceled = False
try:
jobs.join() # Wait for all the work to be done
except KeyboardInterrupt: # May not work on Windows
Qtrac.report("canceling...")
canceled = True
if canceled:
done = results.qsize()
else:
done, filename = output(results)
Qtrac.report("read {}/{} feeds using {} threads{}".format(done, todo,
concurrency, " [canceled]" if canceled else ""))
print()
if not canceled:
webbrowser.open(filename)
示例15: main
def main():
limit = handle_commandline()
filename = os.path.join(tempfile.gettempdir(), "whatsnew.html")
canceled = False
todo = done = 0
with open(filename, "wt", encoding="utf-8") as file:
file.write("<!doctype html>\n")
file.write("<html><head><title>What's New</title></head>\n")
file.write("<body><h1>What's New</h1>\n")
todo, done, canceled = write_body(file, limit)
file.write("</body></html>\n")
Qtrac.report("read {}/{} feeds{}".format(done, todo, " [canceled]" if
canceled else ""))
print()
if not canceled:
webbrowser.open(filename)