curl-and-python
Re: NOSIGNAL confusion
Date: Wed, 8 Jun 2005 10:44:24 +0200
On 6/7/05, Tsai Li Ming <mailinglist_at_ltsai.com> wrote:
> Hi
>
> Looking at one of the example codes, retriever-multi.py.
>
> From the libcurl documentation, I understand NOSIGNAL has to be set to
> 1 when using multi-thread program.
>
> 1. Is retriever-multi considered a mult-thread program?
no. the use of nosignal is not significant to this program. nosignal
tells libcurl to internally use select with timeouts instead of
signals for detecting timeout conditions. however, nosignal is set
to 1 to avoid people from getting into trouble if they use/extend
retriever-multi as part of a multithreaded program -- such bugs are
hard to resolve.
> 2. Since the process is not getting a signal when NOSIGNAL is set to 1,
> why is SIGPIPE being ignored?
python ignores sigpipe by default so ignoring it is not necessary if
you're careful. however, if retriever-multi is used as part of a
multithreaded program or as part of a program which sets sigpipe for
other reasons, setting sigpipe this way makes the implications
explicit. as we all know from the zen of python, explicit is better
than implicit.
> 3. Does the process get a signal when NOSIGNAL is set to 0? I tried the
> following:
nosignal only affects signals managed internally by libcurl.
your program does not send any signal -- simply setting a sigalarm
handler does not cause signals to be sent. rather, consider the
following code:
import pycurl, signal, sys, time, os
def handler(signum, frame):
print '\nSignal handler called with signal', signum
c = pycurl.Curl()
c.setopt(c.URL, sys.argv[1])
c.setopt(pycurl.NOSIGNAL, 1)
signal.signal(signal.SIGALRM, handler)
signal.alarm(1)
time.sleep(0.99)
c.perform()
print 'perform() finished'
time.sleep(1)
c.close()
-------------
when executed (e.g. with www.yahoo.com as argument), the signal
handler is usually invoked after the complete document has been
retrieved. the reason for this behaviour is that python execute
signal handlers for signals occuring during execution of bytecodes
asynchronously. thus, the alarm signal handler in the code above will
not be executed _during_ the execution of perform(), but rather before
or after the bytecode that invokes the perform cal. see
http://docs.python.org/lib/module-signal.html for more details on
signals and python.
hope this helps,
- kjetil
_______________________________________________
http://cool.haxx.se/mailman/listinfo/curl-and-python
Received on 2005-06-08