刷新python getstr()同时刷新(curses in python getstr() while refreshing)

编程入门 行业动态 更新时间:2024-10-26 13:32:23
刷新python getstr()同时刷新(curses in python getstr() while refreshing)

我正在使用curses模块为服务器应用程序编写前端。 由curses返回的主窗口分为2个子窗口。 屏幕的上半部分打印服务器的输出,而底线则使用window.getstr()输入。 有时当我输入文本并且上半部分正在更新时,整个屏幕变得疯狂,随机字符替换现有字符。 是否有特定原因或者是诅咒bug?

I am writing a front end for a server application using the curses module. THe main windows returned by curses is divided into 2 sub-windows. The top half of the screen prints output from the server while the bottom line takes input with window.getstr(). Sometimes when I am entering text and the top half is updating the whole screen goes crazy with random characters replacing the existing characters. Is there a specific cause for this or is it a curses bug?

最满意答案

我猜你在使用一个线程来更新上部显示,而window.getstr()在主线程中运行?

如果是这样,问题是curses终端状态是无法同时从两个不同线程更新的共享资源。 您需要将终端置于非阻塞模式,使用window.getch()来构建输入字符串,并让您的线程将上层窗口更新任务传递给主线程。

I'm guessing you are using a thread to update the upper display while window.getstr() runs in the main thread?

If so, the problem is that the curses terminal state is a shared resource that can't be updated from two different threads simultaneously. You need to put the terminal into non-blocking mode, use window.getch() to build up an input string and have your thread pass the upper window update task to the main thread.

更多推荐

本文发布于:2023-07-04 11:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023626.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:getstr   python   refreshing   curses

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!