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

MinRK benjaminrk at gmail.com
Mon Mar 26 23:10:00 CEST 2012


On Sun, Mar 25, 2012 at 23:05, Ronald Swain <proj_symbian at live.com> wrote:

>  Hello Cornelius,
>
> Thanks for pointing that out. I Used ProcessDevice and it worked the way i
> want, but was not able to understand, some questions:
>
> 1) Does ProcessDevice takes care of doing the clean up work ??
> 2) Is there way i can close the processdevice or i can check if its
> already running ??
>
> I tried terminating the python interpreter ,  but as that is a different
> process i dont this thats going to killed with my old way.
>

ProcessDevice simply sets up sockets and calls zmq.device() via
multiprocessing, which in turn uses fork (or a filthy broken mess on
Windows).  The underlying Process (or Thread) is available as
Device.launcher.  You can query that with dev.launcher.is_alive(),
dev.launcher.pid, etc.  The appropriate references for these objects are
the stdlib docs for
multiprocessing.Process<http://docs.python.org/library/multiprocessing.html#multiprocessing.Process>and
threading.Thread<http://docs.python.org/library/threading.html#threading.Thread>respectively.

The devices default to using `daemon=True`, which means that Python will
try to terminate them on a clean exit (forcefully terminating the parent
doesn't give it the chance to cleanup, and ProcessDevices will continue to
run as orphans in this case).

-MinRK




>
> Thanks,
> Ronald
>
> ------------------------------
> Date: Fri, 23 Mar 2012 10:35:02 -0500
>
> From: cornelius.toole at gmail.com
> To: zeromq-dev at lists.zeromq.org
> Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder
>
> Check out the documentation on devices and pyzmq as well as the zguide
>
> ... whenever i start a zmq.device(zmq.Forwarder), this blocks my
> interpreter, so is there any way of starting a forwarder always as a
> different process or any ways of making it non-blocking.
>
>
> http://zeromq.github.com/pyzmq/devices.html
> http://zguide.zeromq.org/page:all#Intermediates-and-Devices
> --
> Cornelius Toole
> Sent with Sparrow <http://www.sparrowmailapp.com>
>
> On Friday, March 23, 2012 at 12:19 AM, Ronald Swain wrote:
>
>  Hello All,
>
> I had one more small question, whenever i start a
> zmq.device(zmq.Forwarder), this blocks my interpreter, so is there any way
> of starting a forwarder always as a different process or any ways of making
> it non-blocking.
>
> Hope my question is clear.
>
> Thanks & Regards,
> Ronald
>
> ------------------------------
> From: proj_symbian at live.com
> To: zeromq-dev at lists.zeromq.org
> Date: Tue, 20 Mar 2012 12:27:24 +0530
> Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder
>
>  Ok the first question is i am back to zero, so now when my scripts are
> working i am able to send messages, the question of cleaning comes.
>
> i am using the following code for the forwarder and i think thats correct,
> but when i kill the process which is running the forwarder the SIGTERM
> signal is not fired i guess and incoming, outgoing and zmq context is not
> cleaned properly.
>
> code:
>
> import zmq
> import signal
>
>
> # this method handles the termination of the app
> # this handler is responsible for properly cleaning of the ports
> def termSignalHandler(signum,frame):
>     incoming.close()
>     outgoing.close()
>     context.term()
>     print("termSignal Handler Called")
>
> def startForwarder():
>     context = zmq.Context(1)
>     incoming = context.socket(zmq.SUB)
>     outgoing = context.socket(zmq.PUB)
>
>     try:
>         incoming.connect("tcp://127.0.0.1:5559");
>         incoming.setsockopt(zmq.SUBSCRIBE, "")
>     except:
>         print("incoming socket is already open")
>
>     try:
>         outgoing.bind('tcp://127.0.0.1:4449')
>     except:
>         print("outgoing socket is open")
>
>     zmq.device(zmq.FORWARDER, incoming, outgoing)
>
> signal.signal(signal.SIGTERM,termSignalHandler)
> startForwarder()
>
> a proper copy can be found at https://gist.github.com/2132163, can you
> guys tell me what wrong i am doing here.
>
>
>
>
>
> ------------------------------
> From: proj_symbian at live.com
> To: zeromq-dev at lists.zeromq.org
> Date: Tue, 20 Mar 2012 11:23:44 +0530
> Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder
>
>  Hello Cornelius and Justin,
>
> I was at last able to get my forwarder to work and it was my mistake.
>
> My sender code which was like:
>
> def sendMessage():
>     context = zmq.Context()
>     sender = context.socket(zmq.PUB)
>     sender.bind('tcp://127.0.0.1:5558')
>     sender.send("This is the sender")
>
> was the actual problem, i got to know from my reading that call to socket.bind should happen only once, so i changed my sender code to
> something like:
>
> socket = context.socket(zmq.PUB)
>
> socket.bind('tcp://127.0.0.1:4443')
>
> def sendMessage(socket,message):
>     try:
>         socket.send(message)
>     except:
>         print "Unable To Send Message"
>
> and than i was able to send messages but this gets me into two three more problems, i hope you guys will help me out is giving me some
> ideas about this.
>
>
>
>
>
> ------------------------------
> Date: Mon, 19 Mar 2012 13:18:59 -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
>
> From the looks of your code https://gist.github.com/2119078, you define
> functions for sending and receiving messages, but you do not call them,
> like you do with Forwarder.py.
>
> Also for the sake of easier testing, you may want to have your sender
> script to send multiple messages to allow you to see what's going on.
> --
> Cornelius Toole
> Sent with Sparrow <http://www.sparrowmailapp.com>
>
> On Monday, March 19, 2012 at 11:59 AM, Symbian Projects wrote:
>
>  Thanks for your reply cornelius.
>
> I am now using netstat for checking the blocked ports.
>
> Meanwhile i have uploaded the code here https://gist.github.com/2119078
>
> and there is no proprietary code at the moment its the basic code where i
> am trying to get the forwarder working.
>
> and your last point is very valid, i start first the forwarder, than i
> start the receiver and than the sender to send messages. From this the
> point you have mentioned can be a problem.
>
> I will be grateful if you can just have a look at the code its very small
> and let me know if i am doing some wrong.
>
> Regards,
> Ronald
>
> ------------------------------
> Date: Mon, 19 Mar 2012 11:24:40 -0500
> From: cornelius.toole at gmail.com
> To: zeromq-dev at lists.zeromq.org
> Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder
>
>  Ronald,
>
> You can use netstat. You're using windows, right?
> http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/netstat.mspx?mfr=true
>
> As for debugging your code, can you paste the code into a paste bin or
> gist.github?
> Try this for instance: https://gist.github.com/
> You omit out any code that is proprietary if this for work or research.
>
> After you check your ports, you should think about whether the order in
> which ports are being opened is an issue. For instance, your forwarder
> device binds the outgoing port, but what if the  receiver thread starts
> before the device?
>
>
> --
> Cornelius Toole
> Sent with Sparrow <http://www.sparrowmailapp.com>
>
> On Monday, March 19, 2012 at 11:11 AM, Symbian Projects wrote:
>
>  Hello Justin,
>
> Thanks again for reply.
>
>
> I have tried restarting the platform, and i have also checked it in two
> different machines, and in both machine it doesn't work.
>
> I am clue of ideas how to debug this problem as the no of line of code is
> very small too.
>
> Is there any way i  can diagnose that the port is closed or blocked
> something like that.
>
> Thanks,
> Ronald
>
> > From: jhcook at gmail.com
> > Date: Mon, 19 Mar 2012 15:27:12 +0000
> > To: zeromq-dev at lists.zeromq.org
> > Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder
> >
> > If the same code with same libraries no longer works then clearly you
> > have a runtime issue. Have you tried restarting the platforms? Maybe
> > you should have a look at the order in which things are happening. Are
> > you subscribing before the messages are sent?
> >
> > Perhaps its an IP filtering issue. Make sure the ports/proto are not
> blocked.
> >
> > On Mon, Mar 19, 2012 at 10:42 AM, Symbian Projects
> > <proj_symbian at live.com> wrote:
> > > Hello Justin,
> > >
> > > Thanks a lot for your reply.
> > >
> > > Yes i remember for what the thread was started, and that time my
> forwarder
> > > was running great without any problem. I was able to send and receive
> > > messages between my publisher and subscribers.
> > >
> > > Than i added the signals to clean the sockets.
> > >
> > > After that nothing worked and now even the old code is not working,
> which
> > > was used to work earlier.
> > >
> > > I will be very grateful if you just have a look at the code i have
> sent and
> > > tell me is there something wrong in that. Please !!
> >
> > --
> > Justin Cook
> > _______________________________________________
> > 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
> 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
> 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
> 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
> 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
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20120326/c579c072/attachment.htm>


More information about the zeromq-dev mailing list