473,799 Members | 2,935 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HTTPServer and ThreadingMixIn

Hello,

I am having trouble getting the ThreadingMixIn to do what I want.
Looking over the docs (and some old code I wrote which successfully
does what I want), I arrived at the following:

import time
import SocketServer
import BaseHTTPServer

class TheServer(Socke tServer.Threadi ngMixIn,
BaseHTTPServer. HTTPServer):
pass

class TheHandler(Base HTTPServer.Base HTTPRequestHand ler):
def do_GET(self):
print "sleeping.. ."
time.sleep(10)
print "awake!"

if __name__ == "__main__":
theServer = TheServer(('', 8083), TheHandler)
theServer.serve _forever()

I would like this server to print "sleeping.. ." when someone make a
request, waits 10 seconds, then prints "awake!" This works, but it
does not exhibit threading behavior; i.e. it handles the requests in
sequential order:
sleeping...
awake!
sleeping...
awake!

Is there some problem with using the time.sleep() method? Or have I
done something else wrong? Sorry for asking such a simple question,
but it seems I am unable to pinpoint my error.

Thanks.

--Rob

May 15 '06 #1
0 1929

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

Similar topics

0
1160
by: WmGill | last post by:
I'm new to Python, and am dabbling with it to replace a lot of scattered scripts & programs. One thing I want to try is an HTTPserver like in the pydocgui module. This way I can use html to create a user interface to an interactive script (i.e. for access to a MySQL db). Unfortunately, I get lost trying to follow a 2100 line script. Best I can figure tk provides the thread & loop to keep things running, but I'm not familiar enough...
0
1282
by: Will Stuyvesant | last post by:
I have a CGI server written in Python, useful for offline CGI testing. One of my CGI scripts ends with: print 'Location: http://myresourcelocation' print But this does not work with the Python CGI server...and the same script *does* work via internet with the Apache server at my work. Does the BaseHTTPServer.HTTPServer not support the HTTP Location
1
2704
by: Erik Johnson | last post by:
Hi, I am trying to spawn a daemon type program to go off on its own and do some work (asynchoronously) from within an HTTPServer, but I am running into a problem where the web browser (actually a Perl LWP program) still seems to be waiting for more input until the child that is forked in the server finishes (granchild, actually). I don't understand this. I need to be able to have the POST to the server complete and go on even though...
2
6383
by: Tortelini | last post by:
I am making custom web server using HTTPServer and want to be able to access it simultaneously from different computers. To achieve multithreading, I have been experimenting with ThreadingMixIn from SocketServer, but it doesn't seem to work, when I freeze code in one instance it seems to be frozen in second one too (I experimented with time.sleep and while 1 loop). I am using python 2.4 on Windows XP. Does anyone have any suggestions? Do I...
4
3317
by: Andy Leszczynski | last post by:
I need a HTTP server handling long lasting requests e.g. 10-30 seconds. Below is a pice of the code. In order to make the server reponsive while handling othere requests I use SocketServer.ThreadingMixIn. However the problem is the it does not work out. I checked thet a new thread is created for each new connection new, but the main loop seems to be frozen until the prevoius handling ends. What could go wrong?
0
361
by: Frank Abel | last post by:
Hi all! I will build a HTTPServer and dislike that one request is handled at a time (synchronous). So I write: class MyHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): .... .... For log the request and error I create a file and atteched it to the server instance. Then the file log object can be see at RequestHandler instance
1
2443
by: Alvin A. Delagon | last post by:
I'm a simple python webserver based on CGIHTTPServer module: import CGIHTTPServer import BaseHTTPServer import SocketServer import sys import SQL,network from config import * class
0
998
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post by:
In a recent experiment I've done this: from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from wsgiref.simple_server import make_server, demo_app from SocketServer import ThreadingMixIn # Let's make a WSGI server that can use multiple threads. class ThreadedHTTPServer(ThreadingMixIn, HTTPServer): """Handle requests in a separate thread."""
0
195
by: =?UTF-8?B?R2VyaGFyZCBIw6RyaW5n?= | last post by:
Gabriel Genellina wrote: Yes, it does! I was totally on the wrong track. Of course the ThreadingMixin can also be "mixed in" later in the chain. -- Gerhard
0
9688
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
9544
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
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
10259
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...
0
9077
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
7570
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
6809
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();...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
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.