473,804 Members | 3,809 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(CGIHTTP Server.CGIHTTPR equestHandler):
cgi_directories = ['/cgi-bin']
httpd = BaseHTTPServer. HTTPServer(('', 8000), Handler)
httpd.serve_for ever()
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_for ever(). 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 2075
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(CGIHTTP Server.CGIHTTPR equestHandler):
cgi_directories = ['/cgi-bin']
httpd = BaseHTTPServer. HTTPServer(('', 8000), Handler)
httpd.serve_for ever()
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_for ever(). 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********@gma il.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(CGIHTTP Server.CGIHTTPR equestHandler):
cgi_directories = ['/cgi-bin']
httpd = BaseHTTPServer. HTTPServer(('', 8000), Handler)
httpd.serve_for ever()
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 BaseHTTPRequest Handler and override do_GET to handle the
actual request.
Also, can someone reccommend an alternative approach to
httpd.serve_for ever(). 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_re quest() 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.or g> 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
3159
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 (!feof($p2)) print fgets($p2);
13
2356
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 has been in prior months - so I'm really not sure what could cause this. Could anyone suggest some potentiol avenues to explore for reasons that could cause PHP sessions to fail? Thanks for any suggestions!
8
3834
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 googled around a bit, but didn't find much. I want to keep the router's software as it is, but I also would like to have some scripting abilities on it as well (like email the router's IP addy every x hours), etc. I have scripts that run on my...
1
2400
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 the right env settings, Ishould be able to launch mini_httpd like so: mini_httpd -c *.pyand be able to run scripts like so: http://fqdn/simple.pyUsing info from (python) sys.path, multiple get_config_var(..)s and sys.executable, Iwas able to build...
0
1344
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 internet and still have questions. What I'm running into is a serious performance problem with a fairly large (by my standards) database. My system setup is as follows: Dual processor Sun E250 w/1.5GB RAM running Solaris 8 (with all current
12
2363
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
1508
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 form's action=" think.py", would the two scripts be able to talk to each other? Thanks and Best Regards, "Shortash"
3
8517
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 Python, if this is the case (can't seem to do it myself!). Anyway, I'm running a CGI script written in python that tars up the photos in user selected directories (via a form). It's running on Apache 1.3.31.1 on Solaris 5.8. It works well for a...
8
1566
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 possible to use HTA (http:// www.microsoft.com/technet/scriptcenter/hubs/htas.mspx) to achieve my result, however all the documentation just describes doing this with VBScript. So far I've not found anything relevant in Google.
3
1229
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 cannot understand how to run php(CLI is not a solution). Is there a way to solve this problem? I've thought to implement php to HTTPServer-like python module, but as I see it's impossible. Solutions with creating intermediate C-based module is...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10569
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10325
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10315
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9140
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7615
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.