add xheaders config to tornado worker and fix the bug orphaned tornado worker will never s...

In the gunicorn 19.1,  xheaders config is removed, since there is no way to config xheaders any more, I think it can be left  to the tornado application.

Start a tornado app with gunicorn under supervisor, then force kill the master, worker will run forever.

I added a log to the stop_ioloop method like this:

  def stop_ioloop(self):
        self.log.info("callbacks:  %d, timeouts: %d", len(self.ioloop._callbacks), len(self.ioloop._timeouts))
        if not self.ioloop._callbacks and len(self.ioloop._timeouts) <= 1:
            self.ioloop.stop()

Then I found the log in the gunicorn log will like:

2014-08-14 10:54:18 [17430] [INFO] Parent changed, shutting down: <Worker 17430>
2014-08-14 10:54:18 [17372] [INFO] Parent changed, shutting down: <Worker 17372>
2014-08-14 10:54:18 [17373] [INFO] Parent changed, shutting down: <Worker 17373>
2014-08-14 10:54:18 [17430] [INFO] callbacks:  0, timeouts: 2
2014-08-14 10:54:18 [17372] [INFO] callbacks:  0, timeouts: 2
2014-08-14 10:54:18 [17408] [INFO] Parent changed, shutting down: <Worker 17408>
2014-08-14 10:54:18 [17373] [INFO] callbacks:  0, timeouts: 3
2014-08-14 10:54:18 [17408] [INFO] callbacks:  0, timeouts: 2
2014-08-14 10:54:19 [17430] [INFO] Parent changed, shutting down: <Worker 17430>
2014-08-14 10:54:19 [17430] [INFO] callbacks:  0, timeouts: 3
2014-08-14 10:54:19 [17372] [INFO] Parent changed, shutting down: <Worker 17372>
2014-08-14 10:54:19 [17372] [INFO] callbacks:  0, timeouts: 3
2014-08-14 10:54:19 [17373] [INFO] Parent changed, shutting down: <Worker 17373>
2014-08-14 10:54:19 [17373] [INFO] callbacks:  0, timeouts: 4
2014-08-14 10:54:19 [17430] [INFO] callbacks:  0, timeouts: 3
2014-08-14 10:54:19 [17372] [INFO] callbacks:  0, timeouts: 3
2014-08-14 10:54:19 [17408] [INFO] Parent changed, shutting down: <Worker 17408>
2014-08-14 10:54:19 [17408] [INFO] callbacks:  0, timeouts: 3
2014-08-14 10:54:19 [17373] [INFO] callbacks:  0, timeouts: 4
2014-08-14 10:54:19 [17408] [INFO] callbacks:  0, timeouts: 3
2014-08-14 10:54:20 [17430] [INFO] Parent changed, shutting down: <Worker 17430>
2014-08-14 10:54:20 [17430] [INFO] callbacks:  0, timeouts: 4
2014-08-14 10:54:20 [17430] [INFO] callbacks:  0, timeouts: 4
2014-08-14 10:54:20 [17372] [INFO] Parent changed, shutting down: <Worker 17372>
...

The callbacks is always 0 and timeouts will increase forever, since PeriodicCallback will add an timeout to the ioloop, the timeouts will never be zero, so the worker can nerver stop.