[Python-Dev] Re: asyncore 2.1.1/2.2 incompatibility

Carl J. Nobile Carl J.Nobile <cnobile1@twcny.rr.com>
Fri, 22 Mar 2002 21:56:09 -0500 (EST)


This message is in MIME format
--_=XFMail.1.5.0.Linux:20020322215609:7931=_
Content-Type: text/plain; charset=iso-8859-1

Hi all,

I've created two exceptions that will be raised when either a SIGTERM or SIGHUP
is caught. This seems to have solved the problem as the slightly modified
version of my test server, that I've attached, demonstrates. This is a much
more elegant solution to the problem, but I'm still not so sure that the poll
functions should be ignoring EINTR in the way that they do. I wonder how much
code this has broken?

At a minimum something should be said about how this works and how to handle
signals in the asyncore documentation.

Thanks for all your help.

Carl

On 22-Mar-2002 Andrew Kuchling wrote:
> On Fri, Mar 22, 2002 at 01:05:28PM -0500, Guido van Rossum wrote:
>>> program to re-read its configuration file.  This works in 2.2.1
>>                                                            ^^^^^
>>I presume you mean 2.1.1?  From the CVS log it looks like this has
> 
> 2.1.1 is correct; typo on my part.
> 
>>I think if Carl (who submitted 528295) had created a signal handler
>>that raised an exception (rather than simply return), that would
>>probably have had the desired effect -- but I'm not 100% sure.  If it
>>works, it has the added advantage of working with earlier versions of
>>Python too.  I'd like to hear if this workaround works.  Carl?
> 
> Trying it, it looks like it does, and a quick glance at ceval.c agrees.
> The docs for libsignal don't mention anything about what happens when
> you raise an exception in a signal handler, though, and perhaps they
> should.  
> 
> To sum up, it looks like this isn't a bug, and the test program should
> be raising a RereadConfiguration exception instead of relying on
> details of asyncore's loop.  That also means asyncore doesn't need a
> way to be told to exit its loop, since raising an exception does the
> job nicely and Pythonically.
> 
> --amk                                                            
> (www.amk.ca)
> One has no wish to be devoured by alien monstrosities, even in the
> cause of political progress.
>     -- One of the Tribunal, in "Carnival of Monsters"

------------------------------------------------------------------------
E-Mail: Carl J. Nobile <cnobile1@twcny.rr.com>  Home
E-Mail: Carl J. Nobile <cnobile@AppliedTheory.com>  Work
Date: 22-Mar-2002
Time: 21:45:55
------------------------------------------------------------------------

--_=XFMail.1.5.0.Linux:20020322215609:7931=_
Content-Disposition: attachment; filename="testSockets1.py"
Content-Transfer-Encoding: base64
Content-Description: testSockets1.py
Content-Type: application/octet-stream; name=testSockets1.py; SizeOnDisk=3089

CmltcG9ydCBzaWduYWwsIG9zLCB0eXBlcywgc3lzLCB0aW1lLCB0cmFjZWJhY2sKaW1wb3J0IHNv
Y2tldAppbXBvcnQgc2VsZWN0CmltcG9ydCBhc3luY29yZQppbXBvcnQgYXN5bmNoYXQKZnJvbSBl
cnJubyBpbXBvcnQgKgoKY2xhc3MgU2lnbmFsSHVwRXhjZXB0aW9uKEV4Y2VwdGlvbik6CiAgICBw
YXNzCgpjbGFzcyBTaWduYWxUZXJtRXhjZXB0aW9uKEV4Y2VwdGlvbik6CiAgICBwYXNzCgpjbGFz
cyBUQ1BTb2NrZXQoYXN5bmNvcmUuZGlzcGF0Y2hlcik6CiAgICBkZWYgX19pbml0X18oc2VsZiwg
aG9zdCwgcG9ydCk6CiAgICAgICAgYXN5bmNvcmUuZGlzcGF0Y2hlci5fX2luaXRfXyhzZWxmKQog
ICAgICAgIHNlbGYuY3JlYXRlX3NvY2tldChzb2NrZXQuQUZfSU5FVCwgc29ja2V0LlNPQ0tfU1RS
RUFNKQogICAgICAgIHNlbGYuc2V0X3JldXNlX2FkZHIoKQogICAgICAgIHNlbGYuYmluZCgoaG9z
dCwgcG9ydCkpCiAgICAgICAgc2VsZi5saXN0ZW4oNSkKCiAgICBkZWYgaGFuZGxlX2FjY2VwdChz
ZWxmKToKICAgICAgICBUcmFuc2ZlcihzZWxmLCBzZWxmLmFjY2VwdCgpKQoKICAgIGRlZiBsb2co
c2VsZiwgbWVzc2FnZSk6CiAgICAgICAgcGFzcwoKICAgIGRlZiBzZXRTaWduYWwoc2VsZik6CiAg
ICAgICAgc2lnbmFsLnNpZ25hbChzaWduYWwuU0lHVEVSTSwgc2VsZi5fX3NpZ3Rlcm1IYW5kbGVy
KQogICAgICAgIHNpZ25hbC5zaWduYWwoc2lnbmFsLl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
ZXJ2aWNlQ2xpZW50KHNlbGYsIGRhdGEpOgogICAgICAgIHByaW50ICdTZXJ2ZXI6ICVzICVpJyAl
KGRhdGEsIGxlbihkYXRhKSkKICAgICAgICBzZWxmLnB1c2goZGF0YSkKCgoKZGVmIGhhbmRsZUVy
cm9yKGV4Y2VwdGlvbik6CiAgICB0eXBlLCB2YWx1ZSwgdGIgPSBleGNlcHRpb24KICAgIHRyYWNl
YmFjay5wcmludF9leGNlcHRpb24odHlwZSwgdmFsdWUsIHRiKQoKCiMjIyMjIyMjIyMjIyMjIyMj
IyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMKIyBF
eGVjdXRpb24gc3RhcnRzIGhlcmUuCiMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMKaWYgX19u
YW1lX18gPT0gIl9fbWFpbl9fIjoKICAgIHdoaWxlIDE6CiAgICAgICAgcHJpbnQgIkNvbmZpZyBM
b2FkZWQiCgogICAgICAgIHRyeToKICAgICAgICAgICAgc3J2ID0gVENQU29ja2V0KCdsb2NhbGhv
c3QnLCA1MDAyMCkKICAgICAgICAgICAgc3J2LnNldFNpZ25hbCgpCiAgICAgICAgICAgIHNydi5z
dGFydCgpCiAgICAgICAgZXhjZXB0IFNpZ25hbFRlcm1FeGNlcHRpb246CiAgICAgICAgICAgIGJy
ZWFrCiAgICAgICAgZXhjZXB0IFNpZ25hbEh1cEV4Y2VwdGlvbjoKICAgICAgICAgICAgY29udGlu
dWUKICAgICAgICBleGNlcHQ6CiAgICAgICAgICAgIGhhbmRsZUVycm9yKHN5cy5leGNfaW5mbygp
KQoKICAgIHByaW50ICdLZXlTZXJ2ZXIgaXMgdGVybWluYXRpbmcgb24gU0lHVEVSTS4nCiAgICBz
eXMuZXhpdCgwKQo=

--_=XFMail.1.5.0.Linux:20020322215609:7931=_--
End of MIME message