New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gunicorn fails on macOS with inotify installed #1540

Closed
pjvandehaar opened this Issue Jul 11, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@pjvandehaar
Contributor

pjvandehaar commented Jul 11, 2017

inotify isn't compatible with macOS. Ideally pip install inotify would fail on any non-Linux platform, but instead it succeeds and then import inotify.adapters throws AttributeError. If for some reason inotify is installed on macOS, it'd be nice to have gunicorn ignore it.

$ python3 --version
Python 3.6.1

$ pip3 install gunicorn inotify

$ ipython3 -c 'import gunicorn.app.base'
AttributeError                            Traceback (most recent call last)
<ipython-input-1-256ed844b011> in <module>()
----> 1 import gunicorn.app.base

/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py in <module>()
     12 from gunicorn import util
     13 from gunicorn.arbiter import Arbiter
---> 14 from gunicorn.config import Config, get_default_config_file
     15 from gunicorn import debug
     16

/usr/local/lib/python3.6/site-packages/gunicorn/config.py in <module>()
     24 from gunicorn import _compat
     25 from gunicorn.errors import ConfigError
---> 26 from gunicorn.reloader import reloader_engines
     27 from gunicorn import six
     28 from gunicorn import util

/usr/local/lib/python3.6/site-packages/gunicorn/reloader.py in <module>()
     55
     56 try:
---> 57     from inotify.adapters import Inotify
     58     import inotify.constants
     59     has_inotify = True

/usr/local/lib/python3.6/site-packages/inotify/adapters.py in <module>()
      8
      9 import inotify.constants
---> 10 import inotify.calls
     11
     12 # Constants.

/usr/local/lib/python3.6/site-packages/inotify/calls.py in <module>()
     37     return result
     38
---> 39 inotify_init = _LIB.inotify_init
     40 inotify_init.argtypes = []
     41 inotify_init.restype = _check_nonnegative

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ctypes/__init__.py in __getattr__(self, name)
    359         if name.startswith('__') and name.endswith('__'):
    360             raise AttributeError(name)
--> 361         func = self.__getitem__(name)
    362         setattr(self, name, func)
    363         return func

/usr/local/Cellar/python3/3.6.1/Frameworks/Python.framework/Versions/3.6/lib/python3.6/ctypes/__init__.py in __getitem__(self, name_or_ordinal)
    364
    365     def __getitem__(self, name_or_ordinal):
--> 366         func = self._FuncPtr((name_or_ordinal, self))
    367         if not isinstance(name_or_ordinal, int):
    368             func.__name__ = name_or_ordinal

AttributeError: dlsym(0x115d89cc8, inotify_init): symbol not found

(python2 produces the same stacktrace)

To fix this,

try:
    from inotify.adapters import Inotify
    import inotify.constants
    has_inotify = True
except ImportError:
    has_inotify = False

(from here) could be replaced with

try:
    from inotify.adapters import Inotify
    import inotify.constants
    has_inotify = True
except:
    has_inotify = False

or

has_inotify = False
if sys.platform == 'linux':
    try:
        from inotify.adapters import Inotify
        import inotify.constants
        has_inotify = True
    except ImportError:
        pass

@pjvandehaar pjvandehaar changed the title from Cannot import `gunicorn.app.base` on OSX Python3 with inotify installed to Cannot import `gunicorn.app.base` on macOS+Python3 with inotify installed Jul 11, 2017

@pjvandehaar pjvandehaar changed the title from Cannot import `gunicorn.app.base` on macOS+Python3 with inotify installed to Cannot import `gunicorn.app.base` on macOS with inotify installed Jul 11, 2017

@pjvandehaar pjvandehaar changed the title from Cannot import `gunicorn.app.base` on macOS with inotify installed to Gunicorn fails on macOS with inotify installed Jul 11, 2017

@berkerpeksag

This comment has been minimized.

Collaborator

berkerpeksag commented Jul 11, 2017

Thank you for the report. I prefer the third option. Would you like to send a PR?

@berkerpeksag berkerpeksag added the bug :( label Jul 11, 2017

@pjvandehaar

This comment has been minimized.

Contributor

pjvandehaar commented Jul 11, 2017

hramezani added a commit to hramezani/gunicorn that referenced this issue Jul 15, 2017

fofanov pushed a commit to fofanov/gunicorn that referenced this issue Mar 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment