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

Cornelius Toole corntoole at cct.lsu.edu
Fri Mar 16 16:38:11 CET 2012


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 (http://www.sparrowmailapp.com)


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 (mailto:corntoole at cct.lsu.edu)
> 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
> 
> 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
> > 
> > 
> > 
> 
> 
> 
> _______________________________________________ zeromq-dev mailing list 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/190af3fe/attachment.htm>


More information about the zeromq-dev mailing list