C:\appservers\Quixote-1.0c1\server>test1.py 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) es\medusa\asyncore.py:204 >>> def __init__ (self, sock=None, map=None): es\medusa\asyncore.py:205 >>> if sock: es\medusa\asyncore.py:205 >>> if sock: medusa\http_server.py:547 >>> self.create_socket (socket.AF_INET, socket.SOCK_STREAM) es\medusa\asyncore.py:247 >>> def create_socket (self, family, type): es\medusa\asyncore.py:248 >>> self.family_and_type = family, type es\medusa\asyncore.py:249 >>> 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 es\medusa\asyncore.py:250 >>> self.socket.setblocking(0) es\medusa\asyncore.py:251 >>> self._fileno = self.socket.fileno() es\medusa\asyncore.py:252 >>> self.add_channel() es\medusa\asyncore.py:233 >>> def add_channel (self, map=None): es\medusa\asyncore.py:235 >>> if map is None: es\medusa\asyncore.py:236 >>> map=socket_map es\medusa\asyncore.py:237 >>> map [self._fileno] = self es\medusa\asyncore.py:237 >>> map [self._fileno] = self es\medusa\asyncore.py:252 >>> 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) kages\medusa\logger.py:36 >>> def __init__ (self, file, flush=1, mode='a'): kages\medusa\logger.py:37 >>> if type(file) == type(''): kages\medusa\logger.py:44 >>> self.file = file kages\medusa\logger.py:45 >>> self.do_flush = flush kages\medusa\logger.py:45 >>> self.do_flush = flush medusa\http_server.py:554 >>> self.set_reuse_addr() es\medusa\asyncore.py:259 >>> def set_reuse_addr (self): es\medusa\asyncore.py:261 >>> try: es\medusa\asyncore.py:262 >>> self.socket.setsockopt ( es\medusa\asyncore.py:264 >>> self.socket.getsockopt (socket.SOL_SOCKET, socket.SO_REUSEADDR) | 1 es\medusa\asyncore.py:264 >>> self.socket.getsockopt (socket.SOL_SOCKET, socket.SO_REUSEADDR) | 1 medusa\http_server.py:555 >>> self.bind ((ip, port)) es\medusa\asyncore.py:297 >>> def bind (self, addr): es\medusa\asyncore.py:298 >>> self.addr = addr es\medusa\asyncore.py:299 >>> return self.socket.bind (addr) es\medusa\asyncore.py:299 >>> return self.socket.bind (addr) medusa\http_server.py:558 >>> self.listen (1024) es\medusa\asyncore.py:291 >>> def listen (self, num): es\medusa\asyncore.py:292 >>> self.accepting = 1 es\medusa\asyncore.py:293 >>> if os.name == 'nt' and num > 5: es\medusa\asyncore.py:294 >>> num = 1 es\medusa\asyncore.py:295 >>> return self.socket.listen (num) es\medusa\asyncore.py:295 >>> return self.socket.listen (num) medusa\http_server.py:560 >>> host, port = self.socket.getsockname() medusa\http_server.py:561 >>> if not ip: medusa\http_server.py:562 >>> self.log_info('Computing default hostname', 'warning') es\medusa\asyncore.py:368 >>> def log_info (self, message, type='info'): es\medusa\asyncore.py:369 >>> if __debug__ or type != 'info': es\medusa\asyncore.py:370 >>> print '%s: %s' % (type, message) warning: Computing default hostname es\medusa\asyncore.py:370 >>> print '%s: %s' % (type, message) medusa\http_server.py:563 >>> ip = socket.gethostbyname (socket.gethostname()) medusa\http_server.py:564 >>> try: medusa\http_server.py:565 >>> self.server_name = socket.gethostbyaddr (ip)[0] medusa\http_server.py:570 >>> self.server_port = port medusa\http_server.py:571 >>> self.total_clients = counter() ages\medusa\counter.py:18 >>> def __init__ (self, initial_value=0): ages\medusa\counter.py:19 >>> self.value = initial_value ages\medusa\counter.py:19 >>> self.value = initial_value medusa\http_server.py:572 >>> self.total_requests = counter() ages\medusa\counter.py:18 >>> def __init__ (self, initial_value=0): ages\medusa\counter.py:19 >>> self.value = initial_value ages\medusa\counter.py:19 >>> self.value = initial_value medusa\http_server.py:573 >>> self.exceptions = counter() ages\medusa\counter.py:18 >>> def __init__ (self, initial_value=0): ages\medusa\counter.py:19 >>> self.value = initial_value ages\medusa\counter.py:19 >>> self.value = initial_value medusa\http_server.py:574 >>> self.bytes_out = counter() ages\medusa\counter.py:18 >>> def __init__ (self, initial_value=0): ages\medusa\counter.py:19 >>> self.value = initial_value ages\medusa\counter.py:19 >>> self.value = initial_value medusa\http_server.py:575 >>> self.bytes_in = counter() ages\medusa\counter.py:18 >>> def __init__ (self, initial_value=0): ages\medusa\counter.py:19 >>> self.value = initial_value ages\medusa\counter.py:19 >>> self.value = initial_value medusa\http_server.py:577 >>> if not logger_object: medusa\http_server.py:580 >>> if resolver: medusa\http_server.py:583 >>> self.logger = logger.unresolving_logger (logger_object) ages\medusa\logger.py:238 >>> def __init__ (self, logger): ages\medusa\logger.py:239 >>> self.logger = logger ages\medusa\logger.py:239 >>> self.logger = logger medusa\http_server.py:585 >>> self.log_info ( es\medusa\asyncore.py:368 >>> def log_info (self, message, type='info'): es\medusa\asyncore.py:369 >>> if __debug__ or type != 'info': es\medusa\asyncore.py:370 >>> print '%s: %s' % (type, message) info: Medusa (V1.11) started at Fri Jun 18 22:12:05 2004 Hostname: vinj.eswap.com Port:8080 es\medusa\asyncore.py:370 >>> print '%s: %s' % (type, message) medusa\http_server.py:585 >>> self.log_info ( ---------------------------------------------------------------------- starting loop hon23\lib\asyncore.py:180 >>> def loop(timeout=30.0, use_poll=0, map=None): hon23\lib\asyncore.py:181 >>> if map is None: hon23\lib\asyncore.py:182 >>> map = socket_map hon23\lib\asyncore.py:184 >>> if use_poll: hon23\lib\asyncore.py:190 >>> poll_fun = poll hon23\lib\asyncore.py:192 >>> while map: hon23\lib\asyncore.py:192 >>> while map: ---------------------------------------------------------------------- stopping loop C:\appservers\Quixote-1.0c1\server> -----Original Message----- From: Graham Fawcett [mailto:fawcett@teksavvy.com] Sent: Friday, June 18, 2004 4:25 PM To: vineet@eswap.com Cc: quixote-users@mems-exchange.org Subject: Re: [Quixote-users] Re: Help with using medusa 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