From ec301fd43d26207ff0dd9e06925882bc017dc866 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Mon, 11 Jan 2010 02:56:12 +0100 Subject: [PATCH] make gunicorn compatible with py24 and py25 --- gunicorn/worker.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/gunicorn/worker.py b/gunicorn/worker.py index 1259d2d3..0b481e35 100644 --- a/gunicorn/worker.py +++ b/gunicorn/worker.py @@ -32,9 +32,11 @@ import select import signal import socket import sys +import tempfile -import http -import util + +from gunicorn import http +from gunicorn import util log = logging.getLogger(__name__) @@ -50,7 +52,9 @@ class Worker(object): self.ppid = ppid self.socket = socket self.address = socket.getsockname() - self.tmp = os.tmpfile() + fd, tmpname = tempfile.mkstemp() + self.tmp = os.fdopen(fd, "r+b") + self.tmpname = tmpname self.app = app self.alive = True @@ -67,13 +71,19 @@ class Worker(object): def handle_exit(self, sig, frame): sys.exit(-1) + + def _fchmod(self, mode): + if getattr(os, 'fchmod', None): + os.fchmod(self.tmp.fileno(), mode) + else: + os.chmod(self.tmpname, mode) def run(self): self.init_signals() spinner = 0 while self.alive: spinner = (spinner+1) % 2 - os.fchmod(self.tmp.fileno(), spinner) + self._fchmod(spinner) while self.alive: try: @@ -106,7 +116,7 @@ class Worker(object): # Update the fd mtime on each client completion # to signal that this worker process is alive. spinner = (spinner+1) % 2 - os.fchmod(self.tmp.fileno(), spinner) + self._fchmod(spinner) def handle(self, conn, client): req = http.HTTPRequest(conn, client, self.address)