Re: [zeromq-dev] REQ/REP for possibly async comm?

2012-03-27 Thread Michel Pelletier
If not getting a timely response is an exceptional condition, then you
can throw away your REQ socket, create a new REQ socket, connect it
and proceed from there as if it were new.  If it's a common occurrence
then you can do ROUTER<->ROUTER and track the state of requests
yourself.  REQ and REP enforce a simple state, if you need a more
complex state tracking, then you can implement it yourself with
ROUTER.  The way I think of ROUTER is exactly like the hardware device
of the same name, you tell a router's send() where to send the data,
when you recv(), it tells you where it came from.  given that
information you can track your own requests and timeouts for every
given connected peer yourself in a zmq_poll() loop.

-Michel

On Tue, Mar 27, 2012 at 4:35 PM, Andrei Zmievski  wrote:
> Michel,
>
> Thanks for the example. However, from what I understand, this pattern does
> not allow process A to re-send the request in case it has not received the
> response after a certain amount of time, because REQ sockets don't allow
> multiple messages?
>
> -Andrei
>
>>
>> You can use non-blocking ROUTER on a poll loop and REQ or REP on the
>> other end, that way you can handle requests and their responses as
>> they come and as you compute them, respectively.  Whether to use REQ
>> or REP only matters for whichever end starts the conversation.
>> The LRU pattern documented in the guide has a good implementation of
>> this pattern with REQ->ROUTER->REP.  It doesn't sound like you need
>> the actual LRU part of the pattern, just the ROUTER->REQ part.  See
>> the code for an example how to use a ROUTER socket in non-blocking
>> mode in a poll loop to handle out of order patterns like A then B
>> requests but you respond B then A.
>> Start here and read it a few times. :)
>> http://zguide.zeromq.org/page:all#Least-Recently-Used-Routing-LRU-Pattern
>> -Michel
>
>
> ___
> zeromq-dev mailing list
> zeromq-dev@lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
___
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev


Re: [zeromq-dev] does 0mq keep-alive for connections?

2012-03-27 Thread Yi Ding
Hi everyone,

I'm running into a (related?) issue where after a period of being idle, the
first message I send over a PUSH socket gets lost, as in I see it going out
on the sender side, but I don't see it on the receiver side.  Subsequent
messages arrive OK, so that makes me think it may be a related issue.

I'm also connecting via a VPN appliance, so there's some commonalities
here.  This is on ZMQ 2.1.

Thanks,
Yi

On Mon, Jan 23, 2012 at 6:09 PM, Martin Sustrik  wrote:

> On 23/01/12 18:06, Sergey Matveychuk wrote:
>
> > Well, may be it'd better to set it via zmq_setsockopt()?
>
> Yes. I believe so.
>
> Martin
> ___
> zeromq-dev mailing list
> zeromq-dev@lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
___
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev


Re: [zeromq-dev] REQ/REP for possibly async comm?

2012-03-27 Thread Andrei Zmievski
Michel,

Thanks for the example. However, from what I understand, this pattern does
not allow process A to re-send the request in case it has not received the
response after a certain amount of time, because REQ sockets don't allow
multiple messages?

-Andrei


> You can use non-blocking ROUTER on a poll loop and REQ or REP on the
> other end, that way you can handle requests and their responses as
> they come and as you compute them, respectively.  Whether to use REQ
> or REP only matters for whichever end starts the conversation.
> The LRU pattern documented in the guide has a good implementation of
> this pattern with REQ->ROUTER->REP.  It doesn't sound like you need
> the actual LRU part of the pattern, just the ROUTER->REQ part.  See
> the code for an example how to use a ROUTER socket in non-blocking
> mode in a poll loop to handle out of order patterns like A then B
> requests but you respond B then A.
> Start here and read it a few times. :)
> http://zguide.zeromq.org/page:all#Least-Recently-Used-Routing-LRU-Pattern
> -Michel
___
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev


[zeromq-dev] ZMQ not working only when using a jar

2012-03-27 Thread Sabri Skhiri
Hello,

I am using the zmq java binding in my project, I can launch my main class
without any problem from Eclipse, I can make run the ./local_lat.sh in the
perf directory but when I tried to launch my main class from a jar I get a
java.lang.NoClassDefFoundError: org/zeromq/ZMQ

Let me explain
I have just a main that open ZMQ.Sockets
1) On Eclipse I can run my main by just adding the
-Djava.library.path=/usr/local/lib and it starts !
2) on the jzmq directory when I test the local_lat.sh with
java -Djava.library.path=/usr/local/lib -cp
"/usr/local/share/java/zmq.jar:." local_lat  tcp://127.0.0.1: 5 100
it works !
3)But when I want to launch the my main class from the jar I packaged it
does not work:
java -Djava.library.path=/usr/local/lib -cp
"/usr/local/share/java/zmq.jar:." -jar
roq-core-1.0-SNAPSHOT-jar-with-dependencies.jar
org.roqmessaging.core.launcher.MonitorLaunch

Then it throws:
skhiri@sskhiri-K52JU:~/dev/RoQ/RoQ/roq-core/target$
../src/main/resources/startMonitor.sh
Starting monitor process
Starting Monitor on base port 5571, 5800
Exception in thread "main" java.lang.NoClassDefFoundError: org/zeromq/ZMQ
at org.roqmessaging.core.Monitor.(Monitor.java:63)
at
org.roqmessaging.core.launcher.MonitorLauncher.main(MonitorLauncher.java:41)
Caused by: java.lang.ClassNotFoundException: org.zeromq.ZMQ
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

Any clue ? Is it possible to have a different behavior if we launch a
.class directly or from a jar file ?

OS: Ubuntu 11.04
ZMQ Version: 2.1.11

Thanks for the support !

Sabri.
___
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev


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

2012-03-27 Thread MinRK
On Tue, Mar 27, 2012 at 00:03, Ronald Swain  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: benjami...@gmail.com
> Date: Mon, 26 Mar 2012 14:10:00 -0700
>
> To: zeromq-dev@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  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.Processand
> threading.Threadrespectively.
>
> 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.to...@gmail.com
> To: zeromq-dev@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_symb...@live.com
> To: zeromq-dev@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 o

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

2012-03-27 Thread Michel Pelletier
The daemon flag, and every other aspect of the multiprocessing module
is very well documented:

http://docs.python.org/library/multiprocessing.html#multiprocessing.Process.daemon

-Michel

On Tue, Mar 27, 2012 at 4:18 AM, Ronald Swain  wrote:
> Hello all.
>
> I solved the second error myself but i am still confused abt the first
> question.
>
> 
> From: proj_symb...@live.com
> To: zeromq-dev@lists.zeromq.org
> Date: Tue, 27 Mar 2012 09:03:57 +0200
>
> Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder
>
> 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.
> 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: benjami...@gmail.com
> Date: Mon, 26 Mar 2012 14:10:00 -0700
> To: zeromq-dev@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  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.to...@gmail.com
> To: zeromq-dev@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_symb...@live.com
> To: zeromq-dev@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:
>   

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

2012-03-27 Thread Ronald Swain

Hello all.

I solved the second error myself but i am still confused abt the first question.

From: proj_symb...@live.com
To: zeromq-dev@lists.zeromq.org
Date: Tue, 27 Mar 2012 09:03:57 +0200
Subject: Re: [zeromq-dev] FW: Help With Regard To the ZMQ Forwarder







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.
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: benjami...@gmail.com
Date: Mon, 26 Mar 2012 14:10:00 -0700
To: zeromq-dev@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  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.to...@gmail.com
To: zeromq-dev@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_symb...@live.com
To: zeromq-dev@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_symb...

Re: [zeromq-dev] polling for messages

2012-03-27 Thread Alex Zeffertt
Thanks for the info.

-- Alex

On 26 March 2012 20:11, Lourens Naudé  wrote:
> Hi Alex,
>
> That'll be fine - the fd events are edge-triggered and would work with any
> reactor implementation. Just remember to read until completion as the
> notification can be for more than one message (zmq protocol is framed) as
> well. Failure to do so will result in further notifications not being
> triggered.
>
> - Lourens
>
>
> On Monday, March 26, 2012, Pieter Hintjens  wrote:
>> Yes, it should work fine.
>>
>> On Mar 26, 2012 11:44 AM, "Alex Zeffertt" 
>> wrote:
>>>
>>> Hi list,
>>>
>>> I'm considering using czmq in my single threaded application.
>>> However, the application is already using an event driven framework in
>>> which a file descriptor has to be registered along with a callback
>>> that is invoked when it becomes readable.
>>>
>>> My question is: can I use the file descriptor returned by
>>> zsockopt_fd() in this way, or would this break things  when I issue
>>> zframe_recv_nowait()?
>>>
>>> Thanks in advance,
>>>
>>> Alex
>>> ___
>>> zeromq-dev mailing list
>>> zeromq-dev@lists.zeromq.org
>>> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>>>
>>
>
> ___
> zeromq-dev mailing list
> zeromq-dev@lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
___
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev


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

2012-03-27 Thread Ronald Swain

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.
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: benjami...@gmail.com
Date: Mon, 26 Mar 2012 14:10:00 -0700
To: zeromq-dev@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  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.to...@gmail.com
To: zeromq-dev@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_symb...@live.com
To: zeromq-dev@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_symb...@live.com
To: zeromq-dev@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