473,322 Members | 1,259 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,322 software developers and data experts.

improving performance of python webserver running python scripts incgi-bin

I am using a simple python webserver (see code below) to serve up
python scripts located in my cgi-bin directory.

import BaseHTTPServer
import CGIHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = ['/cgi-bin']
httpd = BaseHTTPServer.HTTPServer(('',8000), Handler)
httpd.serve_forever()
This works fine, but now I would like to combine the python scripts
into the server program to eliminate starting the python interpreter
on each script call. I am new to python, and was wondering if there
is a better techique that will be faster.

Also, can someone reccommend an alternative approach to
httpd.serve_forever(). I would like to perform other python functions
(read a serial port, write to an Ethernet port, write to a file, etc.)
inside the web server program above. Is there an example of how to
modify the code for an event loop style of operation where the program
mostly performs my python I/O functions until an HTTP request comes
in, and then it breaks out of the I/O operations to handle the HTTP
request.

thanks
Dale
Jan 11 '08 #1
2 2050
Dale a écrit :
I am using a simple python webserver (see code below) to serve up
python scripts located in my cgi-bin directory.

import BaseHTTPServer
import CGIHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = ['/cgi-bin']
httpd = BaseHTTPServer.HTTPServer(('',8000), Handler)
httpd.serve_forever()
This works fine, but now I would like to combine the python scripts
into the server program to eliminate starting the python interpreter
on each script call. I am new to python, and was wondering if there
is a better techique that will be faster.

Also, can someone reccommend an alternative approach to
httpd.serve_forever(). I would like to perform other python functions
(read a serial port, write to an Ethernet port, write to a file, etc.)
inside the web server program above. Is there an example of how to
modify the code for an event loop style of operation where the program
mostly performs my python I/O functions until an HTTP request comes
in, and then it breaks out of the I/O operations to handle the HTTP
request.
May I suggest that you take a look at more sophisticated solutions, like
either wsgi, CherryPy or Twisted ?
Jan 11 '08 #2
On Thu, 10 Jan 2008 23:17:28 -0800 (PST) Dale <da********@gmail.comwrote:
I am using a simple python webserver (see code below) to serve up
python scripts located in my cgi-bin directory.

import BaseHTTPServer
import CGIHTTPServer
class Handler(CGIHTTPServer.CGIHTTPRequestHandler):
cgi_directories = ['/cgi-bin']
httpd = BaseHTTPServer.HTTPServer(('',8000), Handler)
httpd.serve_forever()
This works fine, but now I would like to combine the python scripts
into the server program to eliminate starting the python interpreter
on each script call. I am new to python, and was wondering if there
is a better techique that will be faster.
You can use BaseHTTPRequestHandler and override do_GET to handle the
actual request.
Also, can someone reccommend an alternative approach to
httpd.serve_forever(). I would like to perform other python functions
(read a serial port, write to an Ethernet port, write to a file, etc.)
inside the web server program above. Is there an example of how to
modify the code for an event loop style of operation where the program
mostly performs my python I/O functions until an HTTP request comes
in, and then it breaks out of the I/O operations to handle the HTTP
request.
Use poll/select/whatever to check if httpd.socket has data available,
and then invoke httpd.handle_request() when it does. Nothing else will
happen while the request is being handled.

The suggestion to check the various frameworks for doing async work is
a good one as well.

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/consulting.html
Independent Network/Unix/Perforce consultant, email for more information.
Jan 11 '08 #3

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

Similar topics

4
by: yawnmoth | last post by:
say i have the following two php scripts: ptest.php: <? $p1 = popen("c:\\php\\php -q hello.php","r"); $p2 = popen("c:\\php\\php -q hello.php","r"); while (!feof($p1)) print fgets($p1); while...
13
by: jamie howard | last post by:
Hello there - we have a fairly busy server and we just started to have problems with PHP sessions failing. We've never had this problem before and to be honist, out server traffic is lower than it...
8
by: Brad Tilley | last post by:
Probably a stupid question, but here goes: Is there any way to get a scaled down version of Python onto a Linksys Wireless router? Are there any projects out there that are doing this? I've...
1
by: Venkat B | last post by:
Hi folks,I have a webserver based on mini_httpd v1.19(http://www.acme.com/software/mini_httpd/).I'd like to run some python-based CGI scripts via this webserver on an RH9 system.In theory, with...
0
by: Jack Coxen | last post by:
------_=_NextPart_001_01C3584E.5FF65B60 Content-Type: text/plain; charset="iso-8859-1" I've gone through the mailing list archives, read the appropriate parts of the manual and searched the...
12
by: rurpy | last post by:
Is there an effcient way (more so than cgi) of using Python with Microsoft IIS? Something equivalent to Perl-ISAPI?
4
by: Shortash | last post by:
Hi Guys, I need some wisdom from you. Is it possible to have PHP pages posting to python scripts on the server side and returning values back to the calling PHP files? Like, if my enterval.php...
3
by: falloutphil | last post by:
Hi, First of all sorry for the double post - this is on the Python page too, but as far as I can see this is an Apache issue now. Mods - feel free to delete the similar titled posts from me on...
8
by: C. (http://symcbean.blogspot.com/) | last post by:
Hi all, I am looking for a way to run PHP scripts without using a webserver (from a MS Windows machine). While there are shareware solutions for doing this, it strikse me that it might be...
3
by: artasis | last post by:
Hi, that is my task: I need to create python webserver-like extension(dll) which will run php and python scripts as plugins. I have no problems with dll creating and run python scripts, but I...
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...
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: 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....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.