From: Ashley E. <as...@si...> - 2006-06-17 01:17:55
|
Hi all ive finally built my first little app, a MySQL process watcher, it works quite will and displays in a way similar to linux 'top'. I have compiled the code into an exe using py2exe so i can distribute it amongst colleagues only problem is, the app cursor is constantly in the waiting state (egg timer under winXP), which doesnt bother me, but if i change focus to another window, or try to move my app window, the process watcher app stops responding and generates a windows error. so, how can i avoid the app from crashing, is this thread related in some way? or simply n00b coding. I have included a copy of the python code that was compiled below. there are other minor things too, like how do i hide the cursor in the app, it currently gets moved to 0,0 on each refresh. kind regards Ash ----------- code here ----------- # tty.py db test # This app shows the active processes running on a MySQL database # Version: 0.1; not thread safe(?) # Author: Ashley Etchell <as...@si...> # first lines just brings in the libraries we use # "curses" being the interface to curses import curses, time, MySQLdb # Initialize the library -- get the "whole screen" window scr = curses.initscr() db = MySQLdb.connect(host="xxxxxxxxxxxxxxxxx",user="xxxxxxx",passwd="xxxxxxxxx",db="mysql") cursor = db.cursor() try: scr.nodelay(1) # make sure getch() is non-blocking scr.leaveok(0) # just leave the cursor where we moved it #max_y, max_x = scr.getmaxyx() # get the size of the screen while True: # Continuous loop y = 1 # set start positions x = 1 scr.addstr(y, 1, 'ID') scr.addstr(y, 8, 'User') scr.addstr(y, 16, 'Host') scr.addstr(y, 40, 'Database') scr.addstr(y, 58, 'Command') scr.addstr(y, 65, 'Time') scr.addstr(y, 73, 'Status') y = y +1 scr.addstr(y, 1, '--') scr.addstr(y, 8, '----') scr.addstr(y, 16, '----') scr.addstr(y, 40, '--------') scr.addstr(y, 58, '-------') scr.addstr(y, 65, '----') scr.addstr(y, 73, '------') y = y +1 cursor.execute("SHOW PROCESSLIST") res = cursor.fetchall() for row in res: #print row (ID,User,Host,Database,Command,Time,Status,SQL) = row scr.addstr(y, 1, "%s" % ID) # ID if User != None: # User scr.addstr(y, 8, User) # else: # scr.addstr(y, 8, 'None') # if Host != None: # Host scr.addstr(y, 16, Host) # else: # scr.addstr(y, 16, 'None') # if Database != None: # Database scr.addstr(y, 40, Database) # else: # scr.addstr(y, 40, 'None') # if Command != None: # Command scr.addstr(y, 58, Command) # else: # scr.addstr(y, 58, 'None') # if Time != None: # Time scr.addstr(y, 65, Time) # else: # scr.addstr(y, 65, 'None') # if Status != None: # Status scr.addstr(y, 73, Status) # else: # scr.addstr(y, 73, 'None') # y = y+1 if SQL != None: scr.addstr(y, 2, "Query: %s" % SQL) # SQL Query y = y+1 y = 1 row=() scr.move(0, 0) # move the cursor to upper/left scr.refresh() # make sure the window is updated scr.clear() time.sleep(1) # wait a while finally: cursor.close() db.close() curses.endwin() # return the terminal to regular state |