Created
September 27, 2012 19:01
-
-
Save dickbrouwer/3795783 to your computer and use it in GitHub Desktop.
ZMQ Context reset for Celery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from celery import signals | |
import zmq | |
import logging | |
log = logging.getLogger("app." + __name__) | |
ZMQ_SOCKET_LINGER = 100 | |
context = zmq.Context() | |
context.linger = ZMQ_SOCKET_LINGER | |
def reset_zmq_context(**kwargs): | |
log.debug("Resetting ZMQ Context") | |
reset_context() | |
signals.worker_process_init.connect(reset_zmq_context) | |
def get_context(): | |
global context | |
if context.closed: | |
context = zmq.Context() | |
context.linger = ZMQ_SOCKET_LINGER | |
return context | |
def reset_context(): | |
global context | |
context.term() | |
context = zmq.Context() | |
context.linger = ZMQ_SOCKET_LINGER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment