python - ZeroMQ + Django & uwsgi issues -
using django, need send message another, separate python program. zeromq seems lightweight , should fit bill this.
however, trying work , ends zeromq: bad address error, when setting socket zmq.push (or else). traceback:
exception type: zmqerror exception value: bad address ... ... sock = context.socket(zmq.push) /usr/local/lib/python2.7/dist-packages/zmq/sugar/context.py in socket s = self._socket_class(self, socket_type) self <zmq.sugar.context.context object @ 0x200dc80> socket_type 8
context made in calling function in models.py, , does:
context = zmq.context() sock = context.socket(zmq.push) < ^ crash here> sock.bind('tcp://127.0.0.1:8921') ...
it launched via
exec uwsgi_python \ --master --pidfile=/tmp/blah.pid \ --chdir=/path/to/site \ --module=program.wsgi:application \ --env django_settings_module=program.settings \ --uid user --gid 1000 \ --socket=/tmp/uwsgi_program.sock \ --chmod-socket \ --vacuum \ --harakiri=20 \ --processes=2 \ --max-requests=5000 \ --die-on-term
also have tried adding --lazy launch script, , didn't help, same error.
the wsgi.py file has
import django.core.handlers.wsgi raven.contrib.django.middleware.wsgi import sentry application = sentry(django.core.handlers.wsgi.wsgihandler())
of course, works fine runserver or, server not using uwsgi.
so seems zeromq context creates invalid somehow. trying modify wsgi.py file generate zeromq context there, using @postfork still don't solve issue, exact same error. however, don't using @postfork, since require separate codepaths depending on if use uwsgi or else, , rather more cleanly, if possible.
what overlooking ?
you have tried right approaches (@postfork, --lazy-apps, --lazy...), unless using outdated uwsgi version can suppose (as see zmq.sugar wrapper in place) need --enable-threads in uwsgi options (but first time seeing it).
the problem arise because zmq context create background thread , thread not inherited after fork().
have tried removing master , using single process (so removing fork() presence) if things go better ?
Comments
Post a Comment