def get(self, count=True):
# prepare a process-safe queue to hold all results
results = multiprocessing.Queue()
# spawn web.py server in another process, have it's dispatch as queue.put method
app = self.app(dispatch=results.put, parsed=True)
t = multiprocessing.Process(target=app.run)
t.start()
# stop condition: if count is a number decrease and loop until 0,
# if count is True, loop forever
while count:
yield results.get()
if type(count) == int:
count -= 1
app.stop()
t.terminate()
评论列表
文章目录