[zeromq-dev] FW: Help With Regard To the ZMQ Forwarder

Cornelius Toole corntoole at cct.lsu.edu
Fri Mar 16 13:35:10 CET 2012


Ronald,

My understanding is that those signals are defined by the operating system and are interrupts that occur when certain events happen. So for instance, if your program was in an infinite loop and the user pressed CTRL-C, an interrupt signal, SIGINT, would be generated. The signal module defines an API to handle those signals for various operating systems.  What you have to do is define a function to handle a particular signal, see this for more information: http://stackoverflow.com/questions/1112343/how-do-i-capture-sigint-in-python The example below includes a SIGINT interrupt handler.

import signal
import sys
import zmq

incoming = None
outgoing = None
context = None

def startForwarder():
    context = zmq.Context(1)
    incoming = context.socket(zmq.SUB)

    try:
        incoming.connect("tcp://127.0.0.1:5551");
        incoming.setsockopt(zmq.SUBSCRIBE, "")
    except:
        print("incoming socket is already open")

    try:
        outgoing = context.socket(zmq.PUB)
        outgoing.bind('tcp://127.0.0.1:5562')
    except:
        print("outgoing socket is also open close it")

    zmq.device(zmq.FORWARDER, incoming, outgoing)
    

def signal_handler(signal, frame):
    global incoming, outgoing, context
    incoming.close()
    outgoing.close()
    context.term()
    sys.exit(0)

signal.signal(signal.SIGINT, signal_handler)

startForwarder()



Ronald, also when you say it runs the first time, but you get a ZMQError subsequently, how are you terminating your program? Your answer to this question will let you know which signals you need to define handlers for.

-- 
Cornelius Toole
Sent with Sparrow (http://www.sparrowmailapp.com) 

-- 
Cornelius Toole
Sent with Sparrow (http://www.sparrowmailapp.com)


On Thursday, March 15, 2012 at 11:36 PM, Symbian Projects wrote:

> Hello Justin
> 
> Can you tell me where these signals are defined, like in PyZMQ or somewhere else i am not able to use them. :-(
> 
> > From: jhcook at gmail.com (mailto:jhcook at gmail.com)
> > Date: Thu, 15 Mar 2012 14:59:31 +0000
> > To: zeromq-dev at lists.zeromq.org (mailto:zeromq-dev at lists.zeromq.org)
> > Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder
> > 
> > At the bottom of the Python docs for signal module:
> > 
> > http://docs.python.org/library/signal.html
> > 
> > On Thu, Mar 15, 2012 at 1:46 PM, Symbian Projects <proj_symbian at live.com (mailto:proj_symbian at live.com)> wrote:
> > > Oh are there any documentation about this signal handlers, from them they
> > > seems to be very useful.
> > >
> > > Or can you help me with a small snippet to use any one of them??
> > 
> > -- 
> > Justin Cook
> > _______________________________________________
> > zeromq-dev mailing list
> > zeromq-dev at lists.zeromq.org (mailto:zeromq-dev at lists.zeromq.org)
> > http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org (mailto:zeromq-dev at lists.zeromq.org)
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
> 
> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120316/e9eb934b/attachment.htm>


More information about the zeromq-dev mailing list