More Problems With Curses

ATS Public Labs xcvx at
Mon Jun 21 19:06:58 EDT 1999


I'm trying to write an IRC client in Python using the curses and
threading modules.  Basically one thread will read user input while the
other threads print the messages received from the servers the user is
connected to.   This works fine if I use print() and input() instead of
curses, but it's annoying because the other threads will print stuff to
the screen in the middle of what you are typing.  However, when I try to
use curses instead, only the user-input thread seems to have control of
the screen; the other threads will hang and not print anything until you
press return.

I wrote the following to try to figure out what's going on:

import time
import threading
import curses

def repd():
  while 1:
    print 'x=%d' % x

while 1:
  print 'got %s' % str

This prints out 'x=0', 'x=1' etc. at one second intervals, and in
addition prints whatever you type as soon as you press return.  However,
if I add the following two lines:


right before I start the thread, then what happens is that 'x=0' gets
printed, and then nothing will get printed again until you type
something and press return, at which point all the 'x=n' messages which
you should have seen get printed all at once.  So, just the act of
initializing curses causes this annoying blocking behavior which I don't

So, what am I doing wrong?  How can I get curses and threading to play
nice with each other?

now-I-know-why-it's-called-"curses"-ly yrs, Cliff

More information about the Python-list mailing list