473,473 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Help me to catch this exception :-)

Hi all,
I have written a slightly modified version of the CGIHTTPServer; the
difference with the module included in the standard python distrubution is
that, since I know that the CGI to be executed is a python script, I
always execute it via the execfile() function, instead of opening a
separate process.
But there's a problem: in the CGI, I'm using the cgitb module to catch
exceptions and send them to the browser. This doesn't work. Here is what
happens when a exception is raised from the CGI:

1) the client (HTTP browser) waits for data, which don't came (while I'd
like the cgitb module to display the exception);
2) the exception is propagated to the CGIHTTPServer, which shows it on
the standard error (where noone will ever see it);
3) when I interrupt the HTTP server with Ctrl+C, the KeyboardInterrupt
exception is sent (beautified by cgitb) to the HTTP browser!!!

I can correct (3) by saving the value of sys.excepthook before the call to
execfile and restoring it in the finally clause, but this doesn't solve my
problem. Is there a way to run a python file as if it were a separate
process? That is, forbidding execfile() to modify anything in the caller?
--
Saluti,
Mardy
http://interlingua.altervista.org

Nov 23 '05 #1
2 1404
I don't know the answer, but I like the problem. :-)

What happens with the standard CGIHttpServer ?

Fuzzyman
http://www.voidspace.org.uk/python/index.shtml

Nov 24 '05 #2
Le die Thu, 24 Nov 2005 07:09:26 -0800, Fuzzyman ha scribite:
I don't know the answer, but I like the problem. :-)

What happens with the standard CGIHttpServer ?


The standard CGIHttpServer uses fork() on Unix and popen() on Windows;
since both these functions run the module in a separate process, the
problem doesn't show up. But on Mac, it uses execfile(), so I guess the
problem is the same.

For the moment, I've come up with a hybrid solution: in
CGIHTTPServer, doing "import cgitb; cgitb.enable()" before the try block
which calls execfile(), and add an empty except clause which prints the
exception:

except:
cgitb.handler()

There's still something not working perfectly, but I think this is close
to the solution.
--
Saluti,
Mardy
http://interlingua.altervista.org

Nov 24 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: kaiwing18 | last post by:
Hi , I have a problem relate to java and database. Could anyone answer me ?Please see the following code. import java.sql.*; public class Result { public static void main(String args) {
8
by: MattP | last post by:
Ok, with the help of some examples found on the web and some minor modifications on our own, we have a simple and working encrypt and decrypt solution. It runs as a service, watches for files with...
3
by: John Ruiz | last post by:
Hello. I was wondering about exceptions and how to throw them within functions/methods and catch them. Suppose that we've got: ----------------------------------------------------------------...
5
by: Jesee | last post by:
I am reading Jeffrey Richter's book "Applied Microsoft .NET Framework programming",i came across "Exception handing". Page 405 says "If the stack overflow occurs within the CLR itself,your...
0
by: Shaggyh | last post by:
hi im needing help with a program im writing to do subnetting i was on before about it and i got some help. the code below wont work for me and i cant think of why not. i was wondering if anyone...
1
by: MikeM | last post by:
We are getting a behavior on a Response.Redirect("SomeUrl", True) that I'm hoping someone can explain. This all refers to the code snip at the end. By the way, this is all VB ASP.NET v1.0 code. ...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
3
by: dibblm | last post by:
Below is current code used. I can only list one directory then move to next. I want to search one more directory further and can't seem to find how to get one deeper. What I want to accomplish is...
1
by: AR123 | last post by:
Hi I want to set up a rotating banner. Not sure how to incorporate my rotating banner code into the code below. I want the rotating banner to be the main feature image? This is set up in...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.