[zeromq-dev] Signal handling in blocking zmq_recv

Brian Granger ellisonbg at gmail.com
Tue Mar 9 20:07:19 CET 2010


I looked a bit more at how Python handles these things.

>From the Python docs:

Although Python signal handlers are called asynchronously as far as
the Python user is concerned, they can only occur between the “atomic”
instructions of the Python interpreter. This means that signals
arriving during long calculations implemented purely in C (such as
regular expression matches on large bodies of text) may be delayed for
an arbitrary amount of time.

To test this I did the following:

s.recv()   # this block for a long time

While this was blocking, I did ctrl-C, and then later sent a message
to this socket to it would become unblocked.

At that point, Python raised KeyboardError (the default sig handler
raises that for ctrl-C).  This simple experiment show that:

1. Python's signal handler is still installed and working properly.
2. When blocking on zmq_recv, the Python interpreter is "not in
control." (the 0MQ C++ code is running) and thus can't respond to the
signal until it gets control.

Thus, I think the only way of resolving this if 0MQ is making out
signals in the IO threads.  Thoughts?

Cheers,

Brian
On Tue, Mar 9, 2010 at 10:59 AM, Chris Wong <chris at chriswongstudio.com> wrote:
>>> When would you want to unblock a blocked zmq_recv()? The only time I can
>>> think of doing that legitimately is when the entire application/component
>>> is going away, in which case we want to change the behaviour of zmq_term()
>>> as discussed in my other email.
>>
>> I agree that most of the time, you would be exiting the application.
>> But, you might want to trigger
>> clean up actions of various sorts, before exiting.
>>
>
> That's what the Ruby's signal handler does AFAIK (not entirely sure though). It has a lot of clean-up stuff to do.  I don't even want to get into the details because it's hurting my head just to think about it. ;-)
>
> One of the thing it does (for sure) is to call the internal "finalize" function on each object in the GC system to do resource cleanup.  Like Java, I don't think it's guaranteed, but I observe that it's currently doing it consistently.
>
> Chris
>
>> Brian
>>
>>
>> --
>> Brian E. Granger, Ph.D.
>> Assistant Professor of Physics
>> Cal Poly State University, San Luis Obispo
>> bgranger at calpoly.edu
>> ellisonbg at gmail.com
>
>



-- 
Brian E. Granger, Ph.D.
Assistant Professor of Physics
Cal Poly State University, San Luis Obispo
bgranger at calpoly.edu
ellisonbg at gmail.com



More information about the zeromq-dev mailing list