title: Where to join threads created in an asynchronous tornado request handler?
body: <p>This one has me a bit baffled.  Fairly new to tornado and threading in python, so I could be completely off the mark with what I'm trying to do here.</p>
  
  <p>Probably best to start with some simplified code:</p>
  
  <pre><code>class Handler(tornado.web.RequestHandler):
  
    def perform(self):
       #do something cuz hey, we're in a thread!
  
    def initialize(self):
      self.thread = None
  
    @tornado.web.asynchronous
    def post(self):
  
      self.thread = threading.Thread(target=self.perform)
      self.thread.start()
  
      self.write('In the request')
      self.finish()
  
    def on_connection_close(self):
      logging.info('In on_connection_close()')
      if self.thread:
        logging.info('Joining thread: %s' % (self.thread.name))
        self.thread.join()
  </code></pre>
  
  <p>My problem is that <code>on_connection_close</code> is never getting called, requests are getting handled just fine.  Secondly, am I doing something terrible introducing threading in this manner?</p>