473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Need help on designing a project

Hi all,
I'm starting to think the way I've implemented my program
(http://www.mardy.it/eligante) is all wrong.
Basically, what I want is a web application, which might run as CGI
scripts in apache (and this is working) or even as a standalone
application, in which case it would use it's own internal webserver.

The question is about this homemade webserver: right now it's a slightly
modified version of the standard CGIHTTPServer module. Since I know all my
CGIs are python scripts, I thought that performance would be best if they
are executed with the execfile command, in the same process as the
webserver.

This works, but my problem is that SQL connections (MySQL or sqlite) don't
get closed when the script execution finishes, and at the next execution
of a CGI they may lock the database (this is especially true with sqlite,
but even mysql on Windows gave me these problems).

I tryed to call atexit.register() from inside the CGI script (in order to
close the connection) but my atexit function get called only when the
webserver itself exits.
So, I'd like to know if there is a quick solution, or if I have to rewrite
the whole mechanism (maybe using some existing framework? which one?).
What I care most, is the ease of installation and use of my program (and
portability). That's why I'm not contented with apache.
--
Saluti,
Mardy
http://interlingua.altervista.org

Dec 1 '05 #1
3 1176
Mardy wrote:
Hi all,
I'm starting to think the way I've implemented my program
(http://www.mardy.it/eligante) is all wrong.
Basically, what I want is a web application, which might run as CGI
scripts in apache (and this is working) or even as a standalone
application, in which case it would use it's own internal webserver.

The question is about this homemade webserver: right now it's a slightly
modified version of the standard CGIHTTPServer module. Since I know all my
CGIs are python scripts, I thought that performance would be best if they
are executed with the execfile command, in the same process as the
webserver.

This works, but my problem is that SQL connections (MySQL or sqlite) don't
get closed when the script execution finishes, and at the next execution
of a CGI they may lock the database (this is especially true with sqlite,
but even mysql on Windows gave me these problems).

I tryed to call atexit.register() from inside the CGI script (in order to
close the connection) but my atexit function get called only when the
webserver itself exits.
So, I'd like to know if there is a quick solution, or if I have to rewrite
the whole mechanism (maybe using some existing framework? which one?).
What I care most, is the ease of installation and use of my program (and
portability). That's why I'm not contented with apache.

The logical solution to your problem appears to be to explicitly close
the database connections at the end of each CGI script. Is there some
reason you can't do this?

Note that if you are using execfile()then the best structure for your
scripts would be something like:

conn = db.open(....)
try:
#do CGI stuff
finally:
conn.close()

to make sure that the connection is always closed. Would this help, do
you think?

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Dec 2 '05 #2
Le die Fri, 02 Dec 2005 11:34:45 +0000, Steve Holden ha scribite:
Note that if you are using execfile()then the best structure for your
scripts would be something like:

conn = db.open(....)
try:
#do CGI stuff
finally:
conn.close()


That was of great help! Thanks!
--
Saluti,
Mardy
http://interlingua.altervista.org

Dec 4 '05 #3
Mardy wrote:
This works, but my problem is that SQL connections (MySQL or sqlite) don't
get closed when the script execution finishes, and at the next execution
of a CGI they may lock the database (this is especially true with sqlite,
but even mysql on Windows gave me these problems).


You should know that there is a severe performance penalty in
opening and closing database onnections. I actually did a
measurement on something similar yesterday, and with open/close
with each database operation, I got 50 operations per second.
If I only opened and closed once, I could manage 1000 operations
per second.

You might want to have a look at something like
http://sqlrelay.sourceforge.net/
Dec 7 '05 #4

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

Similar topics

1
by: Jagadeesh | last post by:
Can anyone help in clearing my doubt Hi, There is a need for me to implement Application Blocks in my project, (Basically 3 tire), the project comprises of UIL, BLL,Business Entities, DAL.....
39
by: Steven T. Hatton | last post by:
I came across this while looking for information on C++ and CORBA: http://www.zeroc.com/ice.html. It got me to wondering why I need two different languages in order to write distributed computing...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
2
by: Sky Sigal | last post by:
Hello: I'm currently messing around, and need as much feedback/help as I can get, trying to find the most economical/graceful way to build usercontrols that rely on styling to look any good... ...
3
by: chris | last post by:
Hallo, I am in need of a replacement for the Microsoft Visual Studio .NET. The reason is quiet simple. I develop forms which are used on different microsoft windows platform, and one...
1
by: slonocode | last post by:
I'm wondering if there are certain processes that I could follow to learn to design better classes? Where could I find these processes? Is designing classes more of an art that comes from...
2
by: Viken Karaguesian | last post by:
Hello all, I don't mean to exclude the rest of the world here, but I think this will be more applicable for me. What's the going rate for freelance web designing in the USA? I know it...
2
by: DC | last post by:
Hi, I have designed some data objects that I want to be filled by several providers. Do these objects typically belong into a seperate project (plus each provider is a separate project)? ...
4
by: christopher.catlin | last post by:
Hi, I'm currently designing a database for a construction co and learning how to use access on the fly. I'm having a few problems with the re- use of data if I link tables using relationships...
1
by: mansisutak | last post by:
I hav a project on library management. I am doing coidng very well,but can't able to make designing of forums(in visual basic) expressive. can u help me by sending some designed forums.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.