Vineet Jain wrote: >>Note the assert. If, for any reason, the http_server doesn't get >>registered with asyncore's socket map, then asyncore.loop() will exit >>automatically, just as you described. That's why the assert is there: >>to test whether this is the case. >> >> from medusa import http_server >> import asyncore >> >> PORT = 8080 >> server = http_server.http_server('', PORT) >> assert len(asyncore.socket_map) > 0, 'server not registered!' >> asyncore.loop() >> >>What happens when you execute it? >> >> > >Gives me the following: > >C:\appservers\Quixote-1.0c1\server>test1.py >warning: Computing default hostname >info: Medusa (V1.11) started at Fri Jun 18 16:19:44 2004 > Hostname: vinjvinj > Port:8080 > >Traceback (most recent call last): > File "C:\appservers\Quixote-1.0c1\server\test1.py", line 6, in ? > assert len(asyncore.socket_map) > 0, 'server not registered!' >AssertionError: server not registered! > OK, that's not right. When you instantiated http_server(), http_server.__init__ should have called asyncore.dispatcher.__init__, which should have called self.add_channel() to add itself to the socket map. But for some reason this didn't happen for you. It could be your Medusa distribution; it could be a somehow-broken asyncore implementation. Okay, since we are on a roll, let's try one more test. This one will run an execution trace starting *before* http_server is initialized. from medusa import http_server import asyncore import inspect import sys def trace_func(frame, event, arg): fn, ln, funcname, context, idx = inspect.getframeinfo(frame) fnln = ('%s%s:%s' % (' ' * 25, fn, ln))[-25:] if context: for line in context: print '%s >>> %s' % (fnln, line.rstrip()) return trace_func PORT = 8080 sys.settrace(trace_func) server = http_server.http_server('', PORT) print '-' * 70, 'starting loop' asyncore.loop() print '-' * 70, 'stopping loop' What you get out of this should look something like this... I've just included the significant lines at the top. medusa\http_server.py:543 >>> def __init__ (self, ip, port, resolver=None, logger_object=None): medusa\http_server.py:544 >>> self.ip = ip medusa\http_server.py:545 >>> self.port = port medusa\http_server.py:546 >>> asyncore.dispatcher.__init__ (self) hon23\lib\asyncore.py:203 >>> def __init__(self, sock=None, map=None): hon23\lib\asyncore.py:204 >>> if sock: hon23\lib\asyncore.py:217 >>> self.socket = None hon23\lib\asyncore.py:217 >>> self.socket = None medusa\http_server.py:547 >>> self.create_socket (socket.AF_INET, socket.SOCK_STREAM) hon23\lib\asyncore.py:249 >>> def create_socket(self, family, type): hon23\lib\asyncore.py:250 >>> self.family_and_type = family, type hon23\lib\asyncore.py:251 >>> self.socket = socket.socket(family, type) ython23\lib\socket.py:152 >>> def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, _sock=None): ython23\lib\socket.py:153 >>> if _sock is None: ython23\lib\socket.py:154 >>> _sock = _realsocket(family, type, proto) ython23\lib\socket.py:155 >>> self._sock = _sock ython23\lib\socket.py:156 >>> self.send = self._sock.send ython23\lib\socket.py:157 >>> self.recv = self._sock.recv ython23\lib\socket.py:158 >>> self.sendto = self._sock.sendto ython23\lib\socket.py:159 >>> self.recvfrom = self._sock.recvfrom ython23\lib\socket.py:159 >>> self.recvfrom = self._sock.recvfrom hon23\lib\asyncore.py:252 >>> self.socket.setblocking(0) hon23\lib\asyncore.py:253 >>> self._fileno = self.socket.fileno() hon23\lib\asyncore.py:254 >>> self.add_channel() hon23\lib\asyncore.py:235 >>> def add_channel(self, map=None): hon23\lib\asyncore.py:237 >>> if map is None: hon23\lib\asyncore.py:238 >>> map = socket_map hon23\lib\asyncore.py:239 >>> map[self._fileno] = self hon23\lib\asyncore.py:239 >>> map[self._fileno] = self hon23\lib\asyncore.py:254 >>> self.add_channel() medusa\http_server.py:549 >>> self.handlers = [] medusa\http_server.py:551 >>> if not logger_object: medusa\http_server.py:552 >>> logger_object = logger.file_logger (sys.stdout) Note the self.add_channel() call at asyncore.py:254. That's what's adding your HTTP server to the asyncore loop. Run the new test, and let's see what you get. -- Graham