Skip to content

Commit

Permalink
make gunicorn compatible with py24 and py25
Browse files Browse the repository at this point in the history
  • Loading branch information
Benoit Chesneau committed Jan 11, 2010
1 parent 3bc5376 commit ec301fd
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions gunicorn/worker.py
Expand Up @@ -32,9 +32,11 @@
import signal
import socket
import sys
import tempfile

import http
import util

from gunicorn import http
from gunicorn import util

log = logging.getLogger(__name__)

Expand All @@ -50,7 +52,9 @@ def __init__(self, workerid, ppid, socket, app):
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

Expand All @@ -67,13 +71,19 @@ def handle_quit(self, sig, frame):

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:
Expand Down Expand Up @@ -106,7 +116,7 @@ def run(self):
# 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)
Expand Down

0 comments on commit ec301fd

Please sign in to comment.