title: Python Multithreading, run two functions at the same time
body: <p>So I'm learning about socket programming and have wrote a nifty little chat server. The problem I am having is that my client cannot read and write at the same time. I'm not too sure how to set this up.</p>
  
  <p>This is what I have so far, I want read() and write() to be running concurrently (It isn't so much about reading and writing at the same time - it's about being able to receive messages while input() hangs waiting for user input.):</p>
  
  <pre><code>import socket 
  import threading
  
  class Client(threading.Thread):
  
      def __init__(self):
          self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
          self.socket.connect(('127.0.0.1', 1234))
          print('Client connected to server')
  
          self.readThread = threading.Thread.__init__(self)
          self.writeThread = threading.Thread.__init__(self)
  
      def read(self):
          data = self.socket.recv(1024)
          if data:
              print('Received:', data)
  
      def write(self):
          message = input()
          self.socket.send(bytes(message, 'utf-8'))
  
  
  client = Client()
  
  while True:
      #do both
  </code></pre>