curses in python getstr() while refreshing

社会主义新天地 提交于 2019-12-01 04:16:18

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/8569878/curses-in-python-getstr-while-refreshing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!