Stopping threads with pending input
Kyle Davis
kiledavis en mail.ru
Mar Ene 3 03:16:22 CET 2006
Hello, I'm new to this mailing list and I'm new using python. I have some
acknowledge on C/C++, Java and other languages. I find python very simple
and very fast to produce working code. But I've found a problem I cannot
behave with it.
I have a class for threading, whose task is to read from sys.stdin and send
it by socket. All goes well during program execution. The problem comes
later, when the program should finish, it keeps running because that thread
is still running. Code is as follows:
class inputReader(Thread):
def __init__(self, sock):
self.sock = sock
self.EOF = 0
self.buffer = ""
self.die = 0
Thread.__init__(self)
def run(self):
while not self.die:
buff = sys.stdin.read(1) #Heres the line keeping the
thread alive, (I think)
if not buff:
EOF = 1
break;
self.sock.send(buff)
self.EOF = 1
def stop(self):
self.die = 1
I think the thread won't finish because it's waiting stdin for bytes to
read.
My question is, how can I kill the thread or something to stopping the
program?
Thanks in advance!
Más información sobre la lista de distribución Python-es