SCGIServer and unusal termination

Eden Kirin eden at bicikl.
Mon Nov 16 13:08:10 CET 2009


Hi there,

I'm playing with SCGIServer 
(http://vmlinux.org/cgi-bin/dwww/usr/share/doc/python-scgi/guide.html), 
everything works just fine, but one thing bothers me. All prints after 
try-except block are executed twice after the Ctrl+C is pressed!

test.py:
#-------------------------
from scgi.scgi_server import SCGIServer

n = 0
print "Starting server."

try:
     SCGIServer().serve()
except (KeyboardInterrupt, SystemExit):
     print "Exception!"

# print lines are executed twice (?!)
n += 1
print "Terminating server, attempt %d." % n
n += 1
print "Check n: %d." % n
#-------------------------

This is the output:

eden at sunce:~/data/project/ScgiServer/src> python test.py
Starting server.
^CException!
Exception!
Terminating server, attempt 1.
Check n: 2.
Terminating server, attempt 1.
Check n: 2.
eden at sunce:~/data/project/ScgiServer/src>


If I put something else in try-except block, code after is executed 
normally:

try:
     while 1:
         pass
except (KeyboardInterrupt, SystemExit):
     print "Exception!"

eden at sunce:~/data/project/ScgiServer/src> python test.py
Starting server.
^CException!
Terminating server, attempt 1.
Check n: 2.
eden at sunce:~/data/project/ScgiServer/src>

Environment is 64bit Ubuntu with Python v2.6.4.

Is there some reasonable explanation for this behaviour? Thanks in advance.

-- 
www.vikendi.net -/- www.supergrupa.com



More information about the Python-list mailing list