I'm showing some live stats from a process with curses. I'm newby with this library, so I followed this example to implement what i need.
I write this small version which summarizes my problem:
import time
import curses
def draw_menu(stdscr):
global data
# Turn cursor off
curses.curs_set(False)
# Rendering text
stdscr.addstr(2, 5, "Help me please")
stdscr.addstr(5, 5, data)
# Refresh the screen
stdscr.refresh()
time.sleep(3)
data = 'some initial value'
for i in xrange(2):
curses.wrapper(draw_menu)
# Do some stuff to update values shown in the menu
data = 'updated value {}'.format(i)
time.sleep(3)
After initial call to draw_menu, I need to update values displayed on menu. While update is running (in this example I used time.sleep), values are removed from window and it goes back to 'normal terminal mode', I don't know why.
I would like to update data while staying all time with this 'help me please' message & data displayed.
I think that I could solve this using threads but, since complete code is far more complicated, I would like to avoid threads.
How can I solve this?