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

Pieter Hintjens ph at imatix.com
Thu Mar 29 06:06:23 CEST 2012


Ronald,

What behavior would help you here? I assume you were not checking for
a return code?

Would an assertion have saved you time? That is a valid use of
assertions, to catch programming errors quickly.

-Pieter

On Wed, Mar 28, 2012 at 11:03 PM, Ronald Swain <proj_symbian at live.com> wrote:
>
> Ok Solved the problem again, by mistake i was trying to call setsockopt on a
> PUB socket. :-)
> ________________________________
> From: proj_symbian at live.com
> To: zeromq-dev at lists.zeromq.org
> Date: Thu, 29 Mar 2012 04:55:18 +0200
>
> Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder
>
> Hello All,
>
> Any help on this i am kind of stuck at this and not able to move ahead.
>
> I tried to search this error but i didnt find any satisfactory results.
>
> Please guide me.
>
> ________________________________
> From: proj_symbian at live.com
> To: zeromq-dev at lists.zeromq.org
> Date: Wed, 28 Mar 2012 12:46:13 +0200
> Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder
>
> Hello MinRK and all,
>
> Again i am getting an issue with unicode with python 3 i thing they have
> something different with relevant to unicode, so i use something like:
>
>         self.receivingSocket = self.zmqContext.socket(zmq.PUB)
>         self.receivingSocket.connect(self._forwaderpubaddress)
>         self.receivingSocket.setsockopt_unicode(zmq.SUBSCRIBE, ' ')
>
> and i get the error like :
>
>  self.receivingSocket.setsockopt_unicode(zmq.SUBSCRIBE,'')
>  File "socket.pyx", line 408, in zmq.core.socket.Socket.setsockopt_unicode
> (zmq\core\socket.c:3994)
>  File "socket.pyx", line 322, in zmq.core.socket.Socket.setsockopt
> (zmq\core\socket.c:3353)
>  zmq.core.error.ZMQError: Invalid argument
>
> This is very confusing. :-(
>
>
> ________________________________
> From: benjaminrk at gmail.com
> Date: Tue, 27 Mar 2012 09:40:38 -0700
> To: zeromq-dev at lists.zeromq.org
> Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder
>
>
>
> On Tue, Mar 27, 2012 at 00:03, Ronald Swain <proj_symbian at live.com> wrote:
>
> Hello MinRK,
>
> Thanks for the reply, now i have two more questions from your answer:
>
> 1) What do you mean b telling daemon=TRUE, does the background process run
> as a infinite loop or something like that.
>
>
> See the docs for what daemon means.  zmq_device is already an infinite loop.
>
>
>
> 2) Now my code was working good in Python 2.7.2 but when i test this on
> python 3.x i get a very weird unicode error i have pasted that below:
>
>   File "socket.pyx", line 285, in zmq.core.socket.Socket.setsockopt
> (zmq\core\socket.c:3017)
> TypeError: unicode not allowed, use setsockopt_unicode
>
> i use following code to start the ProcessDevice:
>
>     pd = ProcessDevice(zmq.FORWARDER,zmq.SUB,zmq.PUB)
>     pd.bind_in("tcp://127.0.0.1:5564")
>     pd.bind_out("tcp://127.0.0.1:4452")
>     pd.setsockopt_in(zmq.SUBSCRIBE, "")
>     pd.start()
>
>
> Thanks,
> Ronald
>
> ________________________________
> From: benjaminrk at gmail.com
> Date: Mon, 26 Mar 2012 14:10:00 -0700
>
> To: zeromq-dev at lists.zeromq.org
> Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder
>
>
>
> 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 and 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
>
> 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
>
> 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
>
> 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
>
>
>
> _______________________________________________ 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
>



More information about the zeromq-dev mailing list