How to debug npyscreen application?

744 views
Skip to first unread message

Федор Белов

unread,
Feb 17, 2015, 6:31:01 PM2/17/15
to npys...@googlegroups.com
Hello. I'm not Python developer - my main language is Java. I would like to implement console application so I choosed npyscreen. I've got one problem - how to debug my application? It tried to use PyCharm but it failed to run it.

Itamar Gal

unread,
Feb 18, 2015, 11:05:16 PM2/18/15
to npys...@googlegroups.com
Hey Федор Белов,

I use Unix (Linux and Mac OS X) exclusively, so I don't know what to do on Windows. I've been redirecting standard output and standard error to files, and that's been working pretty well for me:

# Redirect stdout and stderr to files
import sys
sys
.stdout = open('stdout.log', 'w')
sys
.stderr = open('stderr.log', 'w')

For fancier logging you might want to take a look at the logging and the traceback modules. You might also want to check out the winpdb debugger for live debugging, although I haven't really used it for anything yet, so I can't say very much about it.

- Itamar

Nicholas Cole

unread,
Feb 19, 2015, 3:08:48 AM2/19/15
to npys...@googlegroups.com
Recent versions of npyscreen also allow you to script the input to the
application for testing purposes. See 'Writing Tests' in the
documentation.
> --
> You received this message because you are subscribed to the Google Groups
> "npyscreen" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to npyscreen+...@googlegroups.com.
> To post to this group, send email to npys...@googlegroups.com.
> Visit this group at http://groups.google.com/group/npyscreen.
> For more options, visit https://groups.google.com/d/optout.

Bobby Hines

unread,
Feb 8, 2016, 6:59:41 PM2/8/16
to npyscreen
Itamar, where in your npyscreen code do you open the log files? When I try to do this it blocks the npyscreen application from launching. 

Eris Diskordia

unread,
Feb 12, 2016, 6:40:37 AM2/12/16
to npyscreen
I also liked to redirect STDERR to get a proper Error Logging. The problem is that npyscreen gets the screensize from the stderr fileio. Dunno why.

my quick&dirty fix was in line 117 in file /usr/local/lib/python2.7/dist-packages/npyscreen/proto_fm_screen_area.py

change
mxy, mxx = struct.unpack('hh', fcntl.ioctl(sys.stderr.fileno(), termios.TIOCGWINSZ, 'xxxx'))
to
mxy, mxx = struct.unpack('hh', fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, 'xxxx'))

then you can redirect stderr to a file and leave stdout on the screen for the npyscren/ncurses application.
I am not at the actual version so maybe the line is on another linenumer ... but its exactly the line you would see in the error message.

Nicholas Cole

unread,
Feb 15, 2016, 9:23:24 AM2/15/16
to npys...@googlegroups.com
I'll apply that fix in the main code. Thank you.
> --
> You received this message because you are subscribed to the Google Groups
> "npyscreen" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to npyscreen+...@googlegroups.com.
> To post to this group, send email to npys...@googlegroups.com.
> Visit this group at https://groups.google.com/group/npyscreen.
Reply all
Reply to author
Forward
0 new messages