刷新时在python getstr()中进行诅咒 [英] curses in python getstr() while refreshing

查看:162
本文介绍了刷新时在python getstr()中进行诅咒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用curses模块为服务器应用程序编写前端. curses返回的主窗口分为2个子窗口.屏幕的上半部分显示服务器的输出,而下一行则使用window.getstr()进行输入.有时,当我输入文本而上半部分正在更新时,整个屏幕会因为随机字符替换现有字符而发疯.是否有特定原因?还是诅咒错误?

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()在主线程中运行时正在使用一个线程来更新上部显示吗?

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

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

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.

这篇关于刷新时在python getstr()中进行诅咒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆