问题描述
使用django,我们需要向另一个单独的python程序发送一条消息。
Zeromq似乎是轻量级的,应该适合这个账单。
但是,试图让它工作,它总是以ZeroMQ结束:坏将套接字设置为zmq.PUSH(或其他任何内容)时发生地址错误。
这是追溯:
异常类型:ZMQError
异常值:错误地址
...
...
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 at 0x200dc80>
socket_type 8
上下文是在models.py中的调用函数中进行的,只是:
context = zmq.Context()
sock = context.socket(zmq.PUSH)
< ^在这里崩溃>
sock.bind('tcp://127.0.0.1:8921')
...
它是通过
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 \
- di-on-term
还尝试添加--lazy到启动脚本,这没有帮助,同样的错误。 / p>
wsgi.py文件具有
import django.core.handlers .wsgi
from raven.contrib.django.middleware.wsgi import Sentry
application = Sentry(django.core.handlers.wsgi.WSGIHandler())
当然,一切都适用于runserver或另一台不使用uWSGI的服务器。
所以看来,它创建的zeromq上下文无效。
尝试修改wsgi.py文件以生成一个zeromq上下文,使用@postfork仍然不能解决这个问题,完全相同的错误。然而,我也不喜欢使用@postfork,因为这将需要单独的codepaths,这取决于我们是否使用uWSGI或其他东西,而是更干净地执行。
我忽略了什么?
我尝试了所有不同的选项,最后决定,python uwsgi选项将是最适合我们的设置。有关安装说明,请参见以下
Using django, we need to send a message to another, separate python program.Zeromq seems to be lightweight and should fit the bill for this.
However, trying to get it to work and it always ends up with a ZeroMQ: Bad Address error, when setting the socket to zmq.PUSH (or anything else).This is the 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 at 0x200dc80>
socket_type 8
Context was made in the calling function in models.py, and just does:
context = zmq.Context()
sock = context.socket(zmq.PUSH)
< ^ crash here>
sock.bind('tcp://127.0.0.1:8921')
...
It is 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 to the launch script, and that didn't help, same error.
The wsgi.py file has
import django.core.handlers.wsgi
from raven.contrib.django.middleware.wsgi import Sentry
application = Sentry(django.core.handlers.wsgi.WSGIHandler())
Of course, everything works fine with runserver or, another server not using uWSGI.
So it seems that the zeromq context it creates is invalid somehow.Trying to modify the wsgi.py file to generate a zeromq context there, using @postfork still don't solve this issue, exact same error. However, I also don't like using @postfork, since that would require separate codepaths depending on if we use uWSGI or something else, and rather do this more cleanly, if possible.
What am I overlooking ?
I tried all the different options and finally decided that the python uwsgi option would be the best for our setup. Instructions for the installation can be found at the following site
这篇关于ZeroMQ + Django& uwsgi问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!