[Tutor] More assistance with queues and global variables
Tino Dai
tinoloc at gmail.com
Wed Jul 5 16:49:27 CEST 2006
Hi All,
My project is almost working (and without global variables!), and there
is one more hurdle that I want to jump. That is using the SocketServer
module and passing a queue (or for that matter any kind of variable) to the
handle method. I took a look at SocketServer to see what classes I need to
override/extend, and see that I will be need to extending a couple of inits
and methods out of the TCPServer and the BaseServer class. I don't see an
easy way to do this [passing in a variable] , so I figured that I would
extend the classes. I can to realize that I would be extending not only the
base TCPServer class but also the BaseServer class. My question is: When I
extend those classes, can I put all the methods from both of the classes
into my own extended class or would I need to do something funky?
-Tino
Example:
class BaseServer:
def __init__(self, server_address, RequestHandlerClass):
"""Constructor. May be extended, do not override."""
self.server_address = server_address
self.RequestHandlerClass = RequestHandlerClass
def handle_request(self):
"""Handle one request, possibly blocking."""
try:
request, client_address = self.get_request()
except socket.error:
return
if self.verify_request(request, client_address):
try:
self.process_request(request, client_address)
except:
self.handle_error(request, client_address)
self.close_request(request)
class TCPServer(BaseServer):
address_family = socket.AF_INET
socket_type = socket.SOCK_STREAM
request_queue_size = 5
allow_reuse_address = False
def __init__(self, server_address, RequestHandlerClass):
"""Constructor. May be extended, do not override."""
BaseServer.__init__(self, server_address, RequestHandlerClass)
self.socket = socket.socket(self.address_family,
self.socket_type)
self.server_bind()
self.server_activate()
""" Above are the classes that I will need to extend/override
class MyTCPServer (SockertServer.TCPServer):
"""Would all the extended methods go in this class or would look
different? And how would I get the queue up to BaseServer without overriding
TCPServer's init?
-Tino
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060705/7b08acb0/attachment.htm
More information about the Tutor
mailing list