Permalink
Browse files

Merge pull request #25 from Roguelazer/keep_open_fds

keep open file descriptors to the paths that zygote itself needs open
  • Loading branch information...
2 parents 462d9fe + 9d39481 commit d52d561247ced025c35a991b4ccfe638057225d8 @jaredg jaredg committed Nov 23, 2011
Showing with 12 additions and 3 deletions.
  1. +0 −1 zygote/accounting.py
  2. +11 −1 zygote/handlers.py
  3. +1 −1 zygote/master.py
View
@@ -1,5 +1,4 @@
import datetime
-import errno
import logging
import os
import signal
View
@@ -72,6 +72,16 @@ def get_httpserver(io_loop, port, zygote_master, zygote_base=None):
static_path = os.path.realpath('static')
template_path = os.path.realpath('templates')
+ # We need to ensure that we keep file handles open to the static path
+ # and template path. If they go away (from some kind of clean up) while
+ # the app is still running, we won't be able to serve the status page.
+ # Bad!
+ #
+ # TODO: when implementing #24, these FDs will need to be cleaned up
+ open_fds = []
+ open_fds.append(os.open(static_path, os.O_DIRECTORY|os.O_RDONLY))
+ open_fds.append(os.open(template_path, os.O_DIRECTORY|os.O_RDONLY))
+
JSONHandler.zygote_master = zygote_master
app = tornado.web.Application([('/', HTMLHandler),
('/json', JSONHandler),
@@ -82,4 +92,4 @@ def get_httpserver(io_loop, port, zygote_master, zygote_base=None):
app.settings['worker_sockname'] = zygote_master.sock.getsockname()
http_server = tornado.httpserver.HTTPServer(app, io_loop=io_loop, no_keep_alive=True)
http_server.listen(port)
- return http_server
+ return open_fds, http_server
View
@@ -69,7 +69,7 @@ def __init__(self, sock, basepath, module, num_workers, control_port, applicatio
for sig in (signal.SIGINT, signal.SIGTERM, signal.SIGQUIT):
signal.signal(sig, self.stop)
- zygote.handlers.get_httpserver(self.io_loop, control_port, self, zygote_base=zygote_base)
+ self.open_fds, self.status_http_server = zygote.handlers.get_httpserver(self.io_loop, control_port, self, zygote_base=zygote_base)
def reap_child(self, signum, frame):
"""Signal handler for SIGCHLD. Reaps children and updates

0 comments on commit d52d561

Please sign in to comment.