#!/usr/bin/env python # encoding: utf-8 # # Copyright (c) 2009 Doug Hellmann All rights reserved. # """ """ __version__ = "$Id$" #end_pymotw_header import logging from asyncore_http_client import HttpClient from network_programming import asyncore logging.basicConfig(level=logging.DEBUG, format='%(name)s: %(message)s', ) clients = [ HttpClient('http://www.doughellmann.com/'), ] loop_counter = 0 while asyncore.socket_map: loop_counter += 1 logging.debug('loop_counter=%s', loop_counter) asyncore.loop(timeout=1, count=1)
def handle_write(self): sent = self.send(self.write_buffer) self.logger.debug('handle_write() -> "%s"', self.write_buffer[:sent]) self.write_buffer = self.write_buffer[sent:] def handle_read(self): data = self.recv(8192) self.logger.debug('handle_read() -> %d bytes', len(data)) self.read_buffer.write(data) if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG, format='%(name)s: %(message)s', ) clients = [ HttpClient('http://www.doughellmann.com/'), HttpClient('http://www.doughellmann.com/PyMOTW/about/'), ] logging.debug('LOOP STARTING') asyncore.loop() logging.debug('LOOP DONE') for c in clients: response_body = c.read_buffer.getvalue() print c.url, 'got', len(response_body), 'bytes'