1
# $Id: http_manager.py 270 2004-10-09 10:38:54Z fredrik $
4
# manage a set of http clients
6
# Copyright (c) 2001-2004 by Fredrik Lundh. All rights reserved.
21
def request(self, uri, consumer, extra_headers=None):
22
self.queue.append((uri, consumer, extra_headers))
24
def priority_request(self, uri, consumer, extra_headers=None):
25
self.queue.insert(0, (uri, consumer, extra_headers))
28
for channel in asyncore.socket_map.values():
32
def prioritize(self, priority_uri):
34
for uri, consumer, extra_headers in self.queue:
35
if uri == priority_uri:
37
self.priority_request(uri, consumer, extra_headers)
41
def poll(self, timeout=0.1):
44
for channel in asyncore.socket_map.values():
45
if channel.bytes_in > self.max_size:
46
channel.close() # too much data
48
channel.consumer.http(
49
0, channel, ("HTTPManager", "too much data", None)
53
if channel.timestamp and now - channel.timestamp > self.max_time:
54
channel.close() # too slow
56
channel.consumer.http(
57
0, channel, ("HTTPManager", "timeout", None)
61
# activate up to max_connections channels
62
while self.queue and len(asyncore.socket_map) < self.max_connections:
63
http_client.do_request(*self.queue.pop(0))
64
# keep the network running
65
asyncore.poll(timeout)
66
# return non-zero if we should keep on polling
67
return len(self.queue) or len(asyncore.socket_map)