Search code examples
pythonnetworkingtcptwistedkademlia

Why does raw_input not prompt correctly?


I'm attempting to use the kademlia library featured here: https://github.com/bmuller/kademlia My code is as follows:

from twisted.internet import reactor
from twisted.python import log
from kademlia.network import Server
import sys

log.startLogging(sys.stdout)

def done(result):
        reactor.stop()
        print "Key result:", result

def get(result, server):
        key = raw_input("Key:")
        server.get(key).addCallback(done)

def set(found, server):
        key = raw_input("Key:")
        message = raw_input("Message:")
        server.set(key, message).addCallback(get, server)

server = Server()
server.listen(8468)
server.bootstrap([("xxx.xxx.xxx.xxx", 8468)]).addCallback(set, server)

reactor.run()

Its taking input and operating on that input correctly. However instead of the input prompts displaying correctly. For example KEY: or MESSAGE: I just get a blank line.

What a i doing wrong here?


Solution

  • The logging is interfering with the process's standard out.

    Try removing the line log.startLogging(sys.stdout) and you should find that raw_input() displays the prompt.