SCGIServer and unusal termination

Diez B. Roggisch deets at nospam.web.de
Tue Nov 17 12:30:05 EST 2009


Eden Kirin wrote:

> Diez B. Roggisch wrote:
> 
>>> Is there some reasonable explanation for this behaviour? Thanks in
>>> advance.
>> 
>> I can only guess that SCGIServer does something to stdout. Your code
>> isn't executed twice, so the doubling seems to come from writing it
>> twice.
> 
> Yes I know that code isn't executed twice since the value of n remains
> the same, only print lines are doubled.
> 
>> Try e.g. redirecting stdout and stderr to different files, and see if
>> things appear once in both.
> 
> Redirection of stdout:
> 
> eden at sunce:~/data/project/ScgiServer/test> python test.py 1> output.txt
> ^Ceden at sunce:~/data/project/ScgiServer/test> cat output.txt
> Starting server.
> Exception!
> Terminating server, attempt 1.
> Check n: 2.
> Starting server.
> Exception!
> Terminating server, attempt 1.
> Check n: 2.
> 
> Redirecting stderr creates an empty file. I still haven't found the
> solution.
> 

Then 

 - save a reference to sys.stdout *before* invoking the server
 - compare to it after interruption. If it has changed, you at least know
that somebody messed with it, and can beat him or whatever you see fit.

Diez



More information about the Python-list mailing list