简体   繁体   English

Python-使用Curses在单个终端中拆分异步

[英]Python - Using Curses to split async in single terminal

I have this async script below, what I'd like to do is have it split it's output but in two different sections of the terminal (top and bottom). 我在下面有一个异步脚本,我想做的是将它的输出分割开,但是放在终端的两个不同部分(顶部和底部)中。 I've heard curses is a great way to go about it, but can't find an example that seems to come close to it. 我听说诅咒是解决此问题的好方法,但找不到与之接近的例子。 Would anyone happen to have an idea how to go about this? 会有人碰巧知道如何去做吗? Any help is appreciated! 任何帮助表示赞赏!

if __name__ == '__main__':
    pool = Pool(processes=2)
    for b in a:
        pool.apply_async(os.system,(b,))
    pool.close()
    pool.join()

I would split it up into 3 threads. 我将其分为3个线程。 Two can maintain the text to print in some shared object. 两个可以维护文本以打印在某些共享对象中。 The third thread can do a screen refresh loop: 第三个线程可以执行屏幕刷新循环:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM