Slavik is mistaken. There is a GIL but it doesn't prevent a second thread from running until the first is finished - that would be silly. It ensures that two threads can't modify the same object at the same time by only allowing one thread to be executing at any instant. But in interleaves running threads by switching between them.
I don't know what your problem is but this code example happily accepts both keyboard and socket input.
Code:
import socket
import threading
def listen():
s = socket.socket()
s.bind(("0.0.0.0", 9999))
s.listen(3)
print "listening"
while True:
x, y = s.accept()
print "Got connection from", y
x.send("------Goodbye--------\n")
x.close()
t = threading.Thread(target=listen)
t.start()
print "waiting for kbd"
while True:
s = raw_input()
print "Keyboard says", s
Aah, it occurs to me. Are you perhaps calling the thread's run() method instead of its start() method? run() doesn't start a new thread - it does its work in the context of the calling thread thus trapping it until the run() method terminates. The start() method is the right one to use. start() starts a new thread (which calls run()) and returns immediately, to allow the caller and the new thread to go their separate ways.
Bookmarks