Skip to content

Instantly share code, notes, and snippets.

@dickbrouwer
Created September 27, 2012 19:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dickbrouwer/3795783 to your computer and use it in GitHub Desktop.
Save dickbrouwer/3795783 to your computer and use it in GitHub Desktop.
ZMQ Context reset for Celery
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