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

Symbian Projects proj_symbian at live.com
Sun Mar 18 15:14:15 CET 2012


Hello Cornelius, 

Thanks and that worked well yesterday. but now i am facing a very basic problem. Following is my code for receiver, sender and forwarder device which was working yesterday , but today i am not able to send and receive and message:

Forwarder Device:
     context = zmq.Context(1)

     incoming = context.socket(zmq.SUB)
     incoming.connect('tcp://127.0.0.1:5560')
     incoming.setsockopt_unicode(zmq.SUBSCRIBE, '')

     outgoing = context.socket(zmq.PUB)
     outgoing.bind('tcp://127.0.0.1:4455')

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



sender:
    context = zmq.Context()
    sender = context.socket(zmq.PUB)
    sender.bind('tcp://127.0.0.1:5560')
    sender.send_unicode("This is the sender")

receiver:
    context = zmq.Context()
    receiver = context.socket(zmq.SUB)
    receiver.connect('tcp://127.0.0.1:4455')
    receiver.setsockopt_unicode(zmq.SUBSCRIBE, '')

    while True:
        print(receiver.recv())


I will be greatful if you tell me what i am doing wrong here.

Regards,
Ronald




Date: Fri, 16 Mar 2012 10:38:11 -0500
From: corntoole at cct.lsu.edu
To: zeromq-dev at lists.zeromq.org
Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder


                Ronald,
Can you help me in this. How to catch the Term(software termination signal)
You catch the SIGTERM signal by calling this method: 
signal.signal(signal.SIGTERM, signal_handler)
What you're doing here is saying, "If this signal(first parameter) occurs, call this function(second parameter) to handle it." And so in the function that you define to handle the function, you would put the code you need to clean up the sockets so they can be reused once you restart your program.
-- 
Cornelius Toole
Sent with Sparrow


                 
                On Friday, March 16, 2012 at 9:46 AM, Symbian Projects wrote:
                
                    



Hello ,

Thanks a lot for the great reply appreciated a lot.

At present i am terminating the application by simply closing the python interpreter with close button at the control panel. :-) It will be more mature once i am clear with more ZMQ stuffs.

I have two problems actually, first is getting the signal Justin mentioned in his previous mail.

    1       HUP (hang up)

     2       INT (interrupt)

     3       QUIT (quit)

     6       ABRT (abort)

     9       KILL (non-catchable, non-ignorable kill)

     14      ALRM (alarm clock)

     15      TERM (software termination signal)

Once this is solved i will attempt for the other one.

Can you help me in this. How to catch the Term(software termination signal)

Thanks again



Date: Fri, 16 Mar 2012 07:35:10 -0500
From: corntoole at cct.lsu.edu
To: zeromq-dev at lists.zeromq.org
Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder


                
                    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 signalimport sysimport zmq
incoming = Noneoutgoing = Nonecontext = 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
                
                
-- 
Cornelius Toole
Sent with Sparrow


                  
                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
> Date: Thu, 15 Mar 2012 14:59:31 +0000
> To: 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> 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
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
 		 	   		  
_______________________________________________zeromq-dev mailing listzeromq-dev at lists.zeromq.orghttp://lists.zeromq.org/mailman/listinfo/zeromq-dev
                  
                  
                  
                  
                
                    

                
            
_______________________________________________
zeromq-dev mailing list
zeromq-dev at lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev 		 	   		  
_______________________________________________zeromq-dev mailing listzeromq-dev at lists.zeromq.orghttp://lists.zeromq.org/mailman/listinfo/zeromq-dev
                 
                 
                 
                 
                
                 
                
                    

                
            
_______________________________________________
zeromq-dev mailing list
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/20120318/76490488/attachment.htm>


More information about the zeromq-dev mailing list