title: Can An Object Pass Itself as a Paramter to a Function in Python?
body: <p>So I'm building a game, and I have a message handler that deals (so far) with running the game itself, and now the lobby. Every time a message is sent, a new instance of that message handler is created. For example...</p>
  
  <p>from wshandler.py:</p>
  
  <pre><code>def on_message(self, message):
      MH = protocol.msghandler.HandlerImplementation(self)
      message = tornado.escape.json_decode(message)
      MH.handle_message(message)
  </code></pre>
  
  <p>Now that MH object... it calls a function in the lobby class, which puts them into a queue. The queue is going to be implemented on a thread, that starts when the program is started...</p>
  
  <p>from main.py:</p>
  
  <pre><code>lobby = model.lobby.Lobby()
  threading.Thread(target = lobby.match_players).start()
  </code></pre>
  
  <p>What I'm basically asking is can I do this, in HandlerImplementation...</p>
  
  <pre><code>def join_queue(self, username):
      main.lobby.join_queue(username, self)
  </code></pre>
  
  <p>and this in lobby.py:</p>
  
  <pre><code>def join_queue(self, username, messager):
      self.lock.acquire()
      self.queue.append((username, messager))
      self.lock.release()
  </code></pre>
  
  <p>So that when I'm matching players in lobby.match_players I can basically just do this...</p>
  
  <pre><code>def match_players(self):
      while(True):
          while len(self.queue) &lt; 2: pass
          self.lock.acquire()
          if len(self.queue) &gt;= 2:
              player1 = self.queue.pop(0)
              player2 = self.queue.pop(0)
              player1[1].player_connect(player1[0], player2[0])
              player2[1].player_connect(player2[0], player1[0])
          self.lock.release()
  </code></pre>
  
  <p>Assuming player_connect is a defined function in HandlerImplementation?</p>