我在下面有这个异步脚本,我想做的是将它的输出拆分为终端的两个不同部分(顶部和底部)。我听说 curses 是一个很好的方法,但找不到一个似乎接近它的例子。有人会碰巧知道如何解决这个问题吗?任何帮助表示赞赏!
if __name__ == '__main__':
pool = Pool(processes=2)
for b in a:
pool.apply_async(os.system,(b,))
pool.close()
pool.join()
我在下面有这个异步脚本,我想做的是将它的输出拆分为终端的两个不同部分(顶部和底部)。我听说 curses 是一个很好的方法,但找不到一个似乎接近它的例子。有人会碰巧知道如何解决这个问题吗?任何帮助表示赞赏!
if __name__ == '__main__':
pool = Pool(processes=2)
for b in a:
pool.apply_async(os.system,(b,))
pool.close()
pool.join()
我会把它分成3个线程。二是可以在某个共享对象中维护要打印的文本。第三个线程可以做一个屏幕刷新循环:
while self.active: # application is still running
if self.touched: # Some of the other threads made an update
self.touched = False
self.draw() # Draw both sections of the other two threads
sleep(0.01) # Refresh rate