decorators#

Module: zmq.decorators#

Decorators for running functions with context/sockets.

Added in version 15.3.

Like using Contexts and Sockets as context managers, but with decorator syntax. Context and sockets are closed at the end of the function.

For example:

from zmq.decorators import context, socket

@context()
@socket(zmq.PUSH)
def work(ctx, push):
    ...

Decorators#

zmq.decorators.context(*args, **kwargs)#

Decorator for adding a Context to a function.

Usage:

@context()
def foo(ctx):
    ...

Added in version 15.3.

Parameters:

name (str) – the keyword argument passed to decorated function

zmq.decorators.socket(*args, **kwargs)#

Decorator for adding a socket to a function.

Usage:

@socket(zmq.PUSH)
def foo(push):
    ...

Added in version 15.3.

Parameters:
  • name (str) – the keyword argument passed to decorated function

  • context_name (str) – the keyword only argument to identify context object