From 4f96ccedc16494b9267989525eb0138495d6c4f9 Mon Sep 17 00:00:00 2001 From: Dan Sully Date: Tue, 22 Mar 2011 09:30:54 -0700 Subject: [PATCH] Catch ctypes import errors. --- gunicorn/http/sendfile.py | 18 ++++++++++++------ gunicorn/util.py | 3 +++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gunicorn/http/sendfile.py b/gunicorn/http/sendfile.py index 71b393b8..f410b0c0 100644 --- a/gunicorn/http/sendfile.py +++ b/gunicorn/http/sendfile.py @@ -3,16 +3,22 @@ # This file is part of gunicorn released under the MIT license. # See the NOTICE for more information. -import ctypes -import ctypes.util import errno import os import sys -if sys.version_info >= (2, 6): - _libc = ctypes.CDLL(ctypes.util.find_library("c"), use_errno=True) - _sendfile = _libc.sendfile -else: +# Python on Solaris compiled with Sun Studio doesn't have ctypes. +try: + import ctypes + import ctypes.util + + if sys.version_info >= (2, 6): + _libc = ctypes.CDLL(ctypes.util.find_library("c"), use_errno=True) + _sendfile = _libc.sendfile + else: + _sendfile = None + +except ImportError: _sendfile = None if _sendfile: diff --git a/gunicorn/util.py b/gunicorn/util.py index bef4b935..84b09f59 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -10,6 +10,9 @@ except MemoryError: # selinux execmem denial # https://bugzilla.redhat.com/show_bug.cgi?id=488396 ctypes = None +except ImportError: + # Python on Solaris compiled with Sun Studio doesn't have ctypes + ctypes = None import fcntl import os